Spreadsheet Testdata is a library that can generate template spreadsheet files for testdata classes and read the contents as a list of objects of a testdata class. This way programmers can specify a testdata class and generate a template, which can then be filled in by domain experts. The list that the library generates from the filled in spreadsheet file can then be used for testing purposes.
By default Spreadsheet Testdata supports Excel files by utilizing Apache POI.
By default a testdata class can include members of primitive types (except byte) or their corresponding object wrapper classes, as well as Strings. The class must contain a constructor with all members as parameters in the order they are defined as members.
The library also supports members of complex types that must follow the above constraints. In order to include such a member in the template file it must be annotated with the @Flatten
annotation.
By default the library uses the member names with a uppercased first letters as labels in the template file. Using the @Label
annotation on a field level you can specifiy custom labels.
A template file can be generated using the following method:
SpreadsheetTestdata spreadsheetTestdata = new SpreadsheetTestdata();
spreadsheetTestdata.createTemplate(new File("testdata.xlsx"), TestDataClass.class);
The contents of a testdata file can be read as a list of objects of a testdata class using the following method:
SpreadsheetTestdata spreadsheetTestdata = new SpreadsheetTestdata();
List<TestdataClass> testData = spreadsheetTestdata.read(new File("testdata.xlsx"), TestdataClass.class);
If you want to use custom type mappers next to or instead of the built-in default type mappers, you can write a class that implements the TypeMapper
interface and call the following method before reading or generating a file:
spreadsheetTestdata.registerTypeMapper(new CustomTypeMapper(), CustomMappedClass.class);
If you also use a custom file mapper, type mappers must be registered after registering the respective file mapper.
By default the library uses the built-in PoiFileMapper
which utilizes Apache POI to write and read Excel files.
If you want to use a custom file mapper, you can write a class that implements the FileMapper
interface and call the following method before reading or generating a file:
spreadsheetTestdata.registerFileMapper(new CustomFileMapper());
All registered custom type mappers will be removed when registering a new file mapper.
The preferred way of obtaining our library is https://jitpack.io/. Jitpack allows you to include Spreadsheet Testdata in any project using the Maven or Gradle build systems. For example, a Maven project can depend on Spreadsheet Testdata like this:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.flpa</groupId>
<artifactId>spreadsheet-testdata</artifactId>
<version>v1.0.0-RC1.1</version>
</dependency>
</dependencies>
Contributions to this open source project are welcome. However, since this library is in an early stage there is no dedicated developer documentation beyond this readme and inline comments.
Our preferred workflow for contributions is forking the project and creating pull requests to offer changes via Github. For more information on this process, please refer to the Github documentation.
gradle eclipse
After running this command the project can be imported into Eclipse.
Copyright (c) 2018 Adelina Teofanescu, Florian Patzl, Ralf Rosskopf published under the MIT license
This library uses the following software from other open source projects:
- Apache POI 3.17, Copyright (c) The Apache Software Foundation
license: The Apache Software License, Version 2.0 - SLF4J, Copyright (c) QOS.ch license: The MIT License sources: https://www.slf4j.org/download.html
Copies of all licenses can be found in this file's directory.