This project exercises the following data providers with JUnitParams:
- Excel 2003 OLE documents - a.k.a. Horrible SpreadSheet Format org.apache.poi.hssf.usermodel.*)
- Excel 2007 OOXML (.xlsx) - a.k.a. XML SpreadSheet Format org.apache.poi.xssf.usermodel.*
- OpenOffice SpreadSheet (.ods) example1, example 2
- Custom JSON org.json.JSON
- Create the Excel 2003, Excel 2007 or Open Office Spreadsheet with test parameters e.g.
| ROWNUM | SEARCH | COUNT |
|---|---|---|
| 1 | junit | 100 |
or a json file with the following structure:
{
"test": [{
"keyword": "junit",
"count": 101.0
}, {
"keyword": "testng",
"count": 31.0
}, {
"keyword": "spock",
"count": 11.0
}],
"other_test": [{
"keyword": "not used",
"count": 1.0
}]
}- Annotate the test methods in the following way:
@Test
@ExcelParameters(filepath = "classpath:data_2007.xlsx", sheetName = "", type = "Excel 2007")
public void loadParamsFromEmbeddedExcel2007(double rowNum, String keyword, double count) {
assumeTrue("search", keyword.matches("(?:junit|testng|spock)"));
assertThat((int) count).isGreaterThan(0);
}or
@Test
@ExcelParameters(filepath = "file:src/test/resources/data_2003.xls", sheetName = "", type = "Excel 2003")
public void loadParamsFromFileExcel2003(double rownum, String keyword, double count) {
assumeTrue("search", keyword.matches("(?:junit|testng|spock)"));
assertThat((int) count).isGreaterThan(0);
}or
@Test
@ExcelParameters(filepath = "file:src/test/resources/data.ods", sheetName = "", type = "OpenOffice Spreadsheet")
public void loadParamsFromFileOpenOfficeSpreadsheel(double rowNum,
String keyword, double count) {
assumeTrue("search", keyword.matches("(?:junit|testng|spock)"));
assertThat((int) count).isGreaterThan(0);
}The ExcelParametersProvider class will read all columns from the Excel 2007, Excel 2003 or Open Office spreadhsheet and executes the test for every row of data.
The test developer is responsible for matching the test method argument types and the column data types.
To enable debug messages during the data loading, set the debug flag with @ExcelParameters attribute:
@Test
@ExcelParameters(filepath = "classpath:data_2007.xlsx", sheetName = "", type = "Excel 2007", debug = true)
public void loadParamsFromEmbeddedExcel2007(double rowNum, String keyword,
double count) {
dataTest(keyword, count);
}this will show the following:
0 = A ID
1 = B SEARCH
2 = C COUNT
Skipped the header
Cell Value: "1.0" class java.lang.Double
Cell Value: "junit" class java.lang.String
Cell Value: "104.0" class java.lang.Double
...
Loaded 3 rows
row 0 : [1.0, junit, 104.0]
...NOTE: attributes for column selection and for converting every column type to String is work in progress.
The snapshot versions are deployed to https://oss.sonatype.org/content/repositories/snapshots/com/github/sergueik/junitparams/junit_params/ Release versions status: pending.
To use the snapshot version, add the following to pom.xml:
<dependency>
<groupId>com.github.sergueik.junitparams</groupId>
<artifactId>junit_params</artifactId>
<version>0.0.7-SNAPSHOT</version>
</dependency>
<repositories>
<repository>
<id>ossrh</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>This project and the testNg-DataProviders - have large code overlap for processing spreadsheets and only differ in test methdod annotation details.
The Google Spreadsheet API portion of the project is the work in progress and ifin the absence of client_secret.json (not checked in) some tests fail please simply remove the
src/{main,test}/java/com/github/sergueik/utils- Using Excel/Open Office / JSON as testNG data providers
- testng dataProviders
- TNG/junit-dataprovider - a different TestNG-like dataprovider runner for JUnit and Allure.
- Pragmatists/JunitParams
- junit contribution: test "assumes" annotation to build inter test dependencies
- how to use Google Sheets API to read data from Spreadsheet