{"id":22360358,"url":"https://github.com/sergueik/junit-dataproviders","last_synced_at":"2025-09-08T12:42:50.580Z","repository":{"id":50080261,"uuid":"110400958","full_name":"sergueik/junit-dataproviders","owner":"sergueik","description":"Ports TestNG Excel and ODT data providers to JUnitParams and core Junit  Parameterized test runner","archived":false,"fork":false,"pushed_at":"2024-02-19T00:55:42.000Z","size":342,"stargazers_count":4,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-02-20T00:24:03.080Z","etag":null,"topics":["dependency-injection","json","junit","parameterized-tests","poi"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sergueik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-11-12T03:17:58.000Z","updated_at":"2022-05-24T21:05:34.000Z","dependencies_parsed_at":"2024-02-04T02:22:07.978Z","dependency_job_id":"a5ad0563-caf1-4290-955b-966c4acbbba4","html_url":"https://github.com/sergueik/junit-dataproviders","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergueik%2Fjunit-dataproviders","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergueik%2Fjunit-dataproviders/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergueik%2Fjunit-dataproviders/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sergueik%2Fjunit-dataproviders/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sergueik","download_url":"https://codeload.github.com/sergueik/junit-dataproviders/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228144705,"owners_count":17876160,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-injection","json","junit","parameterized-tests","poi"],"created_at":"2024-12-04T16:15:56.381Z","updated_at":"2024-12-04T16:15:56.898Z","avatar_url":"https://github.com/sergueik.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"###  JUnit-DataProviders\n\n[![BuildStatus](https://travis-ci.org/sergueik/junit-dataproviders.svg?branch=master)](https://travis-ci.org/sergueik/junit-dataproviders)\n\nThis project exercises following data providers with\n[JUnitParams Junit plugin](https://github.com/Pragmatists/JUnitParams)\nand core Junit 4+ `Parameterized` [test runner class](https://junit.org/junit4/javadoc/latest/org/junit/runners/Parameterized.html):\n\n  * Excel 2003 OLE documents - a.k.a. [Horrible SpreadSheet Format](http://shanmugavelc.blogspot.com/2011/08/apache-poi-read-excel-for-use-of.html) `org.apache.poi.hssf.usermodel.*`\n  * Excel 2007 OOXML (.xlsx) [XML SpreadSheet Format](http://howtodoinjava.com/2013/06/19/readingwriting-excel-files-in-java-poi-tutorial/) `org.apache.poi.xssf.usermodel.*`\n  * OpenOffice SpreadSheet (.ods) [Open Document Format for Office Applications](http://www.jopendocument.org/docs/) `org.jopendocument.dom.*`\n  * JSON via [org.json](https://stleary.github.io/JSON-java/) or [com.google.gson](https://www.javadoc.io/doc/com.google.code.gson/gson) (*work in progress*) package\n  * YAML via [snakeyaml](https://github.com/asomov/snakeyaml)\n  * [Google sheet](https://www.google.com/sheets/about/) (experimental).\n\nThe providers can be integrated with Junit 5 tests via adapter (see below).\n\nUnlike core Data Providers in Junit (5?) and TestNg this provider class allows\nflexible uniform data file path modification at runtime through\nenvironment setting which is useful e.g. for enabling one to exercize different test configurations\nfor  __DEV__ / __TEST__ / __UAT__ environments without modifying or recompiling the test suite java code.\nThe technical  details in __Extra Features__ section below.\n\n### Usage with JUnitParams\n\n* Create the __Excel 2003__, __Excel 2007__ or __Open Office__ spreadsheet with some test-specific parameters e.g.\n\n| ROWNUM |    SEARCH   | COUNT |\n|--------|-------------|-------|\n| 1      | __junit__   | 100   |\n| 2      | __testng__  | 30    |\n\nor a JSON file with the following structure:\n```javascript\n[{\n    \"keyword\": \"junit\",\n    \"count\": 101.0\n  }, {\n    \"keyword\": \"testng\",\n    \"count\": 31.0\n  }]\n```\nor\n```\n{\n  \"some test\": [{\n    \"keyword\": \"junit\",\n    \"count\": 101.0\n  }, {\n    \"keyword\": \"testng\",\n    \"count\": 31.0\n  }],\n  \"another test\": [{\n    \"parameter\": \"value\",\n\n  }],\n}\n```\n* Annotate the test methods inteneded to get parameterized, in the following way:\n```java\n@Test\n@ExcelParameters(filepath = \"classpath:data_2007.xlsx\", sheetName = \"\", type = \"Excel 2007\")\npublic void loadParamsFromEmbeddedExcel2007(double rowNum, String keyword, double count) {\n  // test code, e.g. confirm the parameters are passed\n\tassumeTrue(\"search\", keyword.matches(\"(?:junit|testng|spock)\"));\n\tassertThat((int) count).isGreaterThan(0);\n}\n```\nor\n```java\n@Test\n@ExcelParameters(filepath = \"file:src/test/resources/data_2003.xls\", sheetName = \"\", type = \"Excel 2003\")\npublic void loadParamsFromFileExcel2003(double rownum, String keyword, double count) {\n  // test code, e.g. confirm the parameters are passed\n\tassumeTrue(\"search\", keyword.matches(\"(?:junit|testng|spock)\"));\n\tassertThat((int) count).isGreaterThan(0);\n}\n```\nor\n```java\n@Test\n@ExcelParameters(filepath = \"file:${USERPROFILE}/Desktop/data.ods\", sheetName = \"\", type = \"OpenOffice Spreadsheet\")\npublic void loadParamsFromFileOpenOfficeSpreadsheel(double rowNum,\n    String keyword, double count) {\n  // test code, e.g. confirm the parameters are passed\n  assumeTrue(\"search\", keyword.matches(\"(?:junit|testng|spock)\"));\n  assertThat((int) count).isGreaterThan(0);\n}\n```\nor\n```java\n\tprivate final String jsonDataPath = \"file:c:/ProgramData/Temp/data.json\";\n\t@Test\n\t@FileParameters(value = jsonDataPath, mapper = JSONMapper.class)\n\tpublic void loadParamsFromJSONFile(String strCount,\n\t\t\tString strKeyword) {\n    // actual test code\n\t\tdataTest(strCount, strKeyword);\n\t}\n```\nor\n```java\n\tprivate final static String testDataPath = \"file:c:/Users/${env:USERNAME}/Documents/data.ods\";\n\t@Test\n\t@ExcelParameters(filepath = testDataPath, sheetName = \"\", type = \"OpenOffice Spreadsheet\", debug = true)\n\tpublic void loadParamsFromFileOpenOfficeSpreadsheetUsingVariable(\n\t\t\tdouble rowNum, String keyword, double count) {\n\t\tdataTest(keyword, count);\n\t}\n```\nThe `ExcelParametersProvider`-annotated class will read all columns from the __Excel 2007__, __Excel 2003__ or __Open Office__ spreadhsheet\nfrom the file system using relative (to the project directory) or absolute path when `filepath` is defined with a `file:` prefix .\nThe known system environment settings are being interpolated:\n`file:c:/Users/${env:USERNAME}/Documents/data.json`\n`file:${USERPROFILE}`\nfor Excel and Opend Office but not yet for the JSON mapper (*work in progress*)\n\nWhen test data file is placed outside the project directory, it is often desired to have it in \n`Desktop`, `Downloads` or some other directory of the current user.\n\nThe environment variables being OS specific and annotation spec enforcing that every annotation parameter is \na constant expressions makes it a little bit challenging, preventing one from using class variables or static methods - e.g. code like below:\n@Test\n@ExcelParameters(filepath = String.format(\n    \"file:${USERPROFILE}%sDesktop%sdata.ods\",\n    File.separator), sheetName = \"\", type = \"Spreadsheet\", debug = true)\n```\nwill fail with\n```\nThe value for annotation attribute ExcelParameters.filepath must be a constant expression\n```\n\nTherefore __JUnit-DataProviders__ internally converts\nbetween `${USERPRFILE}` and `${HOME}` eliminating the need to tweak the path expressions\nlike `filepath = \"file:${USERPROFILE}/Desktop/data.ods\"` or `filepath = \"file:${HOMEDIR}/Desktop/data.ods\" - both would work across OS.\n\n\nor from inside the jar when `filepath` is defined with a `classpath:` prefix and executes the test for every row of data.\nThe test developer is responsible for matching the test method argument types and the column data types.\n\nSetting the `debug` flag with `@ExcelParameters` attribute would enable debug messages during the data loading:\n```java\n@Test\n@ExcelParameters(filepath = \"classpath:data_2007.xlsx\", sheetName = \"\", type = \"Excel 2007\", debug = true)\npublic void loadParamsFromEmbeddedExcel2007(double rowNum, String keyword,\n    double count) {\n  dataTest(keyword, count);\n}\n```\n\nthis will show the following:\n```shell\n0 = A ID\n1 = B SEARCH\n2 = C COUNT\nSkipped the header\nCell Value: \"1.0\" class java.lang.Double\nCell Value: \"junit\" class java.lang.String\nCell Value: \"104.0\" class java.lang.Double\n...\nLoaded 3 rows\nrow 0 : [1.0, junit, 104.0]\n...\n```\n\nNOTE: attributes for column selection and forcing every column type to primitive `String` type\nare *work in progress*.\n\n### Maven Central\n\nThe snapshot versions are deployed to [https://oss.sonatype.org/content/repositories/snapshots/com/github/sergueik/junitparams/junit_params/](https://oss.sonatype.org/content/repositories/snapshots/com/github/sergueik/junitparams/junit_params/)\nRelease versions status: [pending](https://issues.sonatype.org/browse/OSSRH-36771?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel).\n\nTo use the snapshot version, add the following to `pom.xml`:\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.sergueik.junitparams\u003c/groupId\u003e\n  \u003cartifactId\u003ejunit_dataproviders\u003c/artifactId\u003e\n  \u003cversion\u003e0.0.15-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003crepositories\u003e\n  \u003crepository\u003e\n    \u003cid\u003eossrh\u003c/id\u003e\n    \u003curl\u003ehttps://oss.sonatype.org/content/repositories/snapshots\u003c/url\u003e\n  \u003c/repository\u003e\n\u003c/repositories\u003e\n```\nor, for earlier versions of the jar,\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.github.sergueik.junitparams\u003c/groupId\u003e\n  \u003cartifactId\u003ejunit_params\u003c/artifactId\u003e\n  \u003cversion\u003e0.0.15-SNAPSHOT\u003c/version\u003e\n\u003c/dependency\u003e\n\n\u003crepositories\u003e\n  \u003crepository\u003e\n    \u003cid\u003eossrh\u003c/id\u003e\n    \u003curl\u003ehttps://oss.sonatype.org/content/repositories/snapshots\u003c/url\u003e\n  \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n### Extra Features for JUnitParams Junit plugin\n\nThis data provider overcomes the known difficulty of core TestNG or Junit parameter annotations: developer is\n[not allowed to redefine](https://stackoverflow.com/questions/16509065/get-rid-of-the-value-for-annotation-attribute-must-be-a-constant-expression-me)\nthe dataprovider attributes like in particular the data source path:\n\n```java\npublic static final String dataPath = \"file:src/test/resources/data.json\";\n  @Test\n  @ExcelParameters(filepath = dataPath)\n  public void test( double rowNum, String keyword, double count) {\n   // actual code ot the  test\n  }\n```\nIn the above, one is only allowed to initialize the `testDataPath` to a `String`(or `int`) primitive type, in particular, one can not set\nit differently for Jenkins / Travis automated build environment and IDE like below:\n```java\n\nprivate static final String jsonDataPath = (env.containsKey(\"TRAVIS\")\n    \u0026\u0026 env.get(\"TRAVIS\").equals(\"true\")) ?\n    ? \"file:src/test/resources/data.json\"\n    : \"file:c:/ProgramData/Temp/data.json\";\n@Test\n@FileParameters(value = jsonDataPath, mapper = JSONMapper.class)\npublic void loadParamsFromJSONFile(String strCount, String strKeyword) {\n  dataTest(strCount, strKeyword);\n}\n```\nor\n```java\nprivate static final boolean isCIBuild = (env.containsKey(\"TRAVIS\")\n    \u0026\u0026 env.get(\"TRAVIS\").equals(\"true\")) ? true : false;\n\n@Test\n@ExcelParameters(filepath = isCIBuild ? \"file:src/test/resources/data.ods\"\n    : \"file:${USERPROFILE}/Desktop/data.ods\", sheetName = \"\", type = \"OpenOffice Spreadsheet\", debug = true)\npublic void loadParamsFromFileOpenOfficeSpreadsheet(double rowNum,\n    String keyword, double count) {\n  dataTest(keyword, count);\n}\n```\nwould fail to compile:\n```sh\nCompilation failure: The value for annotation attribute must be a constant expression\n```\nEven declaring the same (pseudo-const) data as a `static final String` in a separate class:\n\n```java\npublic class ParamData {\n  public final static String dataPath = \"file:src/test/resources/data.json\";\n}\n```\nand assigning the result to the variable in the main test class,\n```java\npublic class FileParamsTest {\n\n  private final static String dataPath = ParamData.dataPath;\n```\nwill lead the the same error convinsincg one it likely not doable.\nThis limitation is not observed with the core Junit `Parameterized` test runner class. Porting all data file kinds to use with this provideris\na work in progress, currently only the JSON provider is converted.\n\nHowever it is quite easy to implement this functionality in the data provider class `ExcelParametersProvider` itself by adding an extra class variable named e.g. `testEnvironment` that would receive its value from e.g. the environment variable named `TEST_ENVIRONMENT` and, when non-blank, would override the data file paths which were specified through the `file://` protocol prefix\nand which therefore referred to the system file paths (not to data embedded inside the jar):\nAfter this is done the original test data provider annotation\n```java\n  @Test\n  @ExcelParameters(filepath = \"file:src/test/resources/data.xlsx\")\n  public void test(double rowNum, String keyword, double count) {\n    try {\n    dataTest(keyword, count);\n    } catch (IllegalStateException e) {\n    System.err\n    .println(String.format(\"keyword: %s , cound : %d \", keyword, count));\n    }\n  }\n```\ncombined with environment `TEST_ENVIRONMENT` set to e.g. `dev` will make dataprovider read the test data from `src/test/resources/dev/data.xlsx` rather then `src/test/resources/data.xlsx`.\n\nIt is implemented directly in the `ExcelParametersProvider` provider in a very basic fashion as shown below:\n\n```java\npublic class ExcelParametersProvider implements ParametersProvider\u003cExcelParameters\u003e {\n\n  private final static String testEnvironment = (System.getenv(\"TEST_ENVIRONMENT\") != null) ? System.getenv(\"TEST_ENVIRONMENT\") : \"\";\n```\n\nand\n\n```java\n  public void initialize(ExcelParameters parametersAnnotation, FrameworkMethod frameworkMethod) {\n    filepath = parametersAnnotation.filepath();\n    type = parametersAnnotation.type();\n    sheetName = parametersAnnotation.sheetName();\n    protocol = filepath.substring(0, filepath.indexOf(':'));\n    filename = filepath.substring(filepath.indexOf(':') + 1);\n    debug = parametersAnnotation.debug();\n    if (testEnvironment != null \u0026\u0026 testEnvironment != \"\") {\n      if (protocol.matches(\"file\")) {\n        if (debug) {\n          System.err.println(String.format(\"Amending the %s with %s\", filename,\n              testEnvironment));\n        }\n      }\n      // Inject the directory into the file path\n      String updatedFilename = filename.replaceAll(\"^(.*)/([^/]+)$\", String.format(\"$1/%s/$2\", testEnvironment));\n      filename = updatedFilename;\n    }\n    // ... rest of initialization\n  }\n```\n\nRunning the test in debug mode\n```cmd\ncopy src\\test\\resources\\data.* src\\test\\resources\\dev\\\nset  TEST_ENVIRONMENT=dev\nmvn test\n```\nworks just as expected - in the example the processing of the Open Office data file `data.ods` and Excel 2003 data file `data_2003.xls` driven tests is shown:\n\n```cmd\nAmending the src/test/resources/data.ods with dev =\u003e src/test/resources/dev/data.ods\nReading Open Office Spreadsheet: Employee Data\n```\n```sh\nexport TEST_ENVIRONMENT=test\nmkdir -p src/test/resources/$TEST_ENVIRONMENT\ncp src/test/resources/data* src/test/resources/$TEST_ENVIRONMENT\nmvn test\nAmending the src/test/resources/data_2003.xls with test =\u003e src/test/resources/test/data_2003.xls\ncreateDataFromExcel2003: Reading Excel 2003 sheet: Employee Data\n```\n\nOne can easily tweak this behavior further: e.g. turn the name `TEST_ENVIRONMENT` of the key envirnment variable into a separate parameter or define environment specifics via property file (this is work in progress). Similar changes are available for [testNg-DataProviders](https://github.com/sergueik/testng-dataproviders).\n\n### Usage with JUnit Parameterized runnner\n\n.\n\nInstance Constructor and Class propetry injection annotations for test\nparameterization are basically supported by\n[Junit 4 onward](https://github.com/junit-team/junit4/wiki/parameterized-tests) via an `org.junit.runners.Parameterized` class.\nHowever the core JUnit wiki does not mention storing test data in external data file which is entirely possible with core JUnit Parameterized tests:\n\ninstead of hard coding the data in the test class\n```java\n@RunWith(Parameterized.class)\npublic class StraightParameterizedConstructorTest extends DataTest {\n\n\t@Parameters\n\tpublic static Collection\u003cObject[]\u003e data() {\n\t\treturn Arrays.asList(new Object[][] { { 1.0, \"junit\", 204 }});\n\t}\n\n\tprivate double rowNum;\n\tprivate String keyword;\n\tprivate int count;\n\n\t// constructor injection\n\tpublic StraightParameterizedConstructorTest(double rowNum, String keyword, int count) {\n\t\tthis.rowNum = rowNum;\n\t\tthis.keyword = keyword;\n\t\tthis.count = count;\n\t}\n```\none can define a singleton class based on one of the classes currently available in `com.github.sergueik.junitparams`:\n```\npublic class DataSource {\n\n\tprivate static DataSource instance = new DataSource();\n\n\tprivate DataSource() {\n\t}\n\n\tpublic static DataSource getInstance() {\n\t\treturn instance;\n\t}\n\n\t// De-serialize the rowset of String data parameters from the JSON file from\n\t// the provided path property\n\t// for later become injected in the test via @Parameters collection\n\tpublic Collection\u003cObject[]\u003e getdata() {\n\n\t\ttry {\n\t\t\t// temporarily store a replica of code from JSONMapper class\n\t\t\treturn Arrays.asList(createDataFromJSON());\n\t\t} catch (JSONException e) {\n\t\t\tif (debug) {\n\t\t\t\tSystem.err.println(\"Failed to load data from datafile: \" + dataFile);\n\t\t\t}\n\t\t\treturn new ArrayList\u003cObject[]\u003e();\n\t\t}\n\t}\n\n\tpublic Object[][] createDataFromJSON {\n  // read and parse JSON\n  }\n\tpublic Object[][] createDataFromYAML {\n  // read and parse YAML\n  }\n```\nand then set the instance of `DataSource` class within the `Test` class with path to the data,\noptionally with other paratemetes like column selection:\n\n```java\n@RunWith(Parameterized.class)\npublic class DataProviderClassParameterizedPropertiesInjectionTest extends DataTest {\n\n\tprivate static DataSource dataSource = DataSource.getInstance();\n\tprivate static String dataFile = \"src/test/resources/data.json\";\n\n\t@Parameters\n\tpublic static Collection\u003cObject[]\u003e data() {\n\t\tdataSource.setDataFile(dataFile);\n\t\treturn dataSource.getdata();\n\t}\n\n  private String rowNum;\n\tprivate String keyword;\n\tprivate String count;\n\n\tpublic DataProviderClassParameterizedConstructorTest(String rowNum,\n\t\t\tString keyword, String count) {\n\t\tthis.rowNum = rowNum;\n\t\tthis.keyword = keyword;\n\t\tthis.count = count;\n\t}\n\n\t@Test\n\tpublic void parameterizedTest() {\n\t\ttry {\n\t\t\tdataTest(count, keyword);\n\t\t} catch (IllegalStateException e) {\n\t\t\tSystem.err\n\t\t\t\t\t.println(String.format(\"keyword: %s , count : %d \", keyword, count));\n\t\t}\n\t}\n```\n\nThe only downside is that, at least with JSON and YAML data files, the only supported `@parameter` data type\nis the `String` primitive type.\n\nThe other minor known issue when loading from JSON the column order is not fully predictable and so is\nbetter be enforced through an extra property (that is *work in progress*, addressed already for YAML).\n\n### Note\n\nThis project and the [testNg-DataProviders](https://github.com/sergueik/testng-dataproviders) -\nhave large code overlap for processing spreadsheets, evolve in parallel and only differ in low level\ntest methdod annotation details.\n\nNote: the [JUnitParams](https://github.com/Pragmatists/JUnitParams) project seems to have been dormant for quite some time,\nbut the PR is in the works.\n\n### Apache POI compatibility\n\n  * The default version of the supported Apache POI is __3.17__.\n  * Project can be compiled with latest release of Apache POI __4.1.0__ with the help of profile `poi410`.\n  * Older versions of the package require minor code refactoring. Note that you may also have to clear the other versions of poi and poi-ooxml jars from maven cache '~/.m2/repository'\n  * Creating branches and tags is a work in progress.\n\n\n### Filtering Data Rows for JUnitParams\n\nIn addition to using *every row* of spreadsheet as test parameter one may create a designated column which value\nwould be indicating to use or skip that row of data, like:\n\n\n\n| ROWNUM |    SEARCH    | COUNT |ENABLED\n|--------|--------------|-------|-------\n| 1      | __junit__    | 100   | 1\n| 2      | __testng__   | 30    | 1\n| 3      | __spock__    | 20    | 0\n| 4      | __mockito__  | 41    | 1\n\nand annotate the method like\n\n```java\n@Test\n@ExcelParameters(filepath = \"file:src/test/resources/filtered_data.ods\",\nsheetName = \"Filtered Employee Data\", type = \"OpenOffice Spreadsheet\",\ndebug = true, controlColumn = \"ENABLED\", withValue = \"1\")\npublic void loadParamsFilteredByColumn(\n    double rowNum, String keyword, double count) {\n  dataTest(keyword, count);\n}\n```\n\n\nwith this data setting only rows 1,2 and 4 from the data extract above would be used as `loadParamsFilteredByColumn` test method parameters.\nThe control column itself is not passed to the subject test method.\nCurrently this functionality is implemented for __OpenOffice__ spreadsheet only,  in the __junit__ data provider.\nRemaining format and testng provider data filtering is a work in progress.\nThis feature of storing more then one set of tests in one spreadsheet and picking the ones which column is set to a specified value\n has been inspired by some python [post](https://docs.pytest.org/en/latest/fixture.html#parametrizing-fixtures)\nand the [forum (in Russian)(http://software-testing.ru/forum/index.php?/topic/37870-kastomizatciia-parametrizatcii-v-pytest/).\n\n### Junit 5 Adapter\n\nTo use the Excel and other data providers with Jnit5 `@ParameterizedTest` one can embed an [adapter](https://www.baeldung.com/java-adapter-pattern) \ninto the `@MethodSource` method (for simlicity the needed arguments made class-level static)\n\n```java\n\nprivate final static String filepath = \"classpath:data2_2007.xlsx\";\nprivate final static String sheetName = \"\";\nprivate final static String type = \"Excel 2007\";\nprivate final static boolean debug = false;\nprivate final static String controlColumn = \"\";\nprivate final static String withValue = \"\";\nprivate static final ExcelParameters parametersAnnotation = new ExcelParameters() {\n\t@Override\n\tpublic String filepath() {\n\t\treturn filepath;\n\t}\n\n\t@Override\n\tpublic Class\u003c? extends Annotation\u003e annotationType() {\n\t\t// NOTE: the method needed for the interface is Junit 4 legacy:\n\t\t// Returns the annotation type of this annotation.\n\t\treturn null;\n\t}\n\n\t@Override\n\tpublic String sheetName() {\n\t\treturn sheetName;\n\t}\n\n\t@Override\n\tpublic String type() {\n\t\treturn type;\n\t}\n\n\t@Override\n\tpublic boolean loadEmptyColumns() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean debug() {\n\t\treturn debug;\n\t}\n\n\t@Override\n\tpublic String controlColumn() {\n\t\treturn controlColumn;\n\t}\n\n\t@Override\n\tpublic String withValue() {\n\t\treturn withValue;\n\t}\n};\n\n// adapter\nprivate static Stream\u003cObject\u003e testData() {\n\tExcelParametersProvider provider = new ExcelParametersProvider();\n\n\ttry {\n\t\tClass\u003c?\u003e _class = Class.forName(\"com.github.sergueik.junit5params.CurrentMethodDataTest\");\n\t\tMethod _method = _class.getMethod(\"dummy\", String.class);\n\t\tFrameworkMethod _frameworkMedhod = new FrameworkMethod(_method);\n\t\tprovider.initialize(parametersAnnotation, _frameworkMedhod);\n\t} catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) {\n\t\tSystem.err.println(\"Exception (ignored): \" + e.getMessage());\n\t\t// e.printStackTrace();\n\t} catch (java.lang.NullPointerException e) {\n\t\t// for unsatisfied Excel Parameter properties\n\t\te.printStackTrace();\n\t}\n\tObject[] parameters = provider.getParameters();\n\tif (debug) {\n\t\tSystem.err.println(String.format(\"Received %d parameters\", parameters.length));\n\t}\n\tif (debug) {\n\t\tfor (int cnt = 0; cnt != parameters.length; cnt++) {\n\t\t\tObject[] row = (Object[]) parameters[cnt];\n\t\t\tSystem.err.println(String.format(\"parameter # %d: %s\", cnt, String.valueOf(row[0])));\n\t\t}\n\t}\n\treturn Stream.of(parameters);\n\n}\n```\nNOTE: the `frameworkMethod` argument  in `initialize` \nseems to be a legacy\n - represents a method on a test class to be invoked\n  at the appropriate point in test execution.\n\t\tSuch methods are usually annotated via\n\t\t`@Test`, `@Before`, `@After`, `@BeforeClass`, `@AfterClass`, etc.\nTherefore add a dummy public method just for the adapter needs\n\n```java\nstatic public void dummy(String data) {\n\n}\n\n```\nthen inject paramers as [usual](https://www.baeldung.com/parameterized-tests-junit-5):\n```java\n@ParameterizedTest\n@MethodSource(\"testData\")\npublic void test(Object param) {\n\t// TODO: debug being called\n\tassertThat(param, notNullValue());\n\tSystem.err.println(\"Parameter: \" + param.toString());\n}\n```\n\nThis will produce:\n```sh\nParameter: junit\nParameter: testng\nParameter: spock\n```\n\nNOTE: for this test only, leave just ine column of data in Excel file. Converion of multi parameter annotations is a work in proggess.\n### Work in Progress\n\n  * rename `JSONMapper` that is implementing a somewhat limited [DataMapper](http://javadox.com/pl.pragmatists/JUnitParams/1.0.4/junitparams/mappers/DataMapper.html)\n  interface to `JSONFileParameters` and construct the new class`JSONParameterProvider` which would fully implement `ParametersProvider\u003cJSONParameters\u003e` all the way for feature parity with the `ExcelParametersProvider`.\n  * produce Javadoc\n  * fix legacy JSON code\n  * add more YAML data providers\n\n\n### See Also\n\n  * [Introduction to JUnitParams](https://www.baeldung.com/junit-params)\n  * Using Excel,Open Office,JSON as [testNG data providers](https://github.com/sergueik/testng-dataproviders)\n  * [testng dataProviders](http://testng.org/doc/documentation-main.html#parameters-dataproviders)\n  * [TNG/junit-dataprovider](https://github.com/TNG/junit-dataprovider) - a different TestNG-like dataprovider runner for JUnit and Allure.\n  * [OpenOffice SpreadSheet example1](http://www.programcreek.com/java-api-examples/index.php?api=org.jopendocument.dom.spreadsheet.Sheet), [example 2](http://half-wit4u.blogspot.com/2011/05/read-openoffice-spreadsheet-ods.html)\n  * [Pragmatists/JunitParams](https://github.com/Pragmatists/JUnitParams)\n  * [junit contribution: test \"assumes\" annotation to build inter test dependencies](https://github.com/junit-team/junit.contrib/tree/master/assumes)\n  * [XLS Test - Excel testing library](https://github.com/codeborne/xls-test)\n  * [Selenium data driven testing with Excel](https://www.swtestacademy.com/data-driven-excel-selenium/)\n  * [using google spreadsheet with java](https://www.baeldung.com/google-sheets-java-client)\n  * [JUnit 4 Wiki about Parameterization of test classes](https://github.com/junit-team/junit4/wiki/parameterized-tests)\n  * [JUnit - Parameterized Test intro ](https://www.tutorialspoint.com/junit/junit_parameterized_test.htm).\n  * [Junit test runners summary](https://github.com/junit-team/junit4/wiki/test-runners)\n  * [YamlDataProviderImpl](http://paypal.github.io/SeLion/html/java-docs/1.0.0/dataproviders-apis/index.html?com/paypal/selion/platform/dataprovider/impl/YamlDataProviderImpl.html) YAML data provider in `com.paypal.selion.platform.dataprovider`\n  * [Examples of Fillo SQL DSL](https://github.com/GladsonAntony/Fillo-Examples)  for Excel spreadsheet-backed Select and Update operations.\n  * [JUnit4, JUnit5, TestNG comparison](https://www.baeldung.com/junit-vs-testng), covers parameteterized tests\n  * JUnit5 test selector annotation [article](https://habr.com/ru/post/464881/)(in Russian) and the [repository](https://github.com/bvn13/JavaLessons/tree/master/springboot2-junit5-skiptest)\n  * [JUnit5 test execution order support](https://junit.org/junit5/docs/current/user-guide/#writing-tests-test-execution-order) and [discussion](https://automated-testing.info/t/junit5-zapusk-serii-testov-strogo-posledovatelno-ili-v-polzovatelskom-poryadke-varianty/18609)(in Russian)\n  * [Jackcess](https://jackcess.sourceforge.io) java library for working with MS Access databases\n  * [memory-optimizied](https://github.com/alibaba/easyexcel) rewrite of Apache poi\n  * [guide](https://www.baeldung.com/parameterized-tests-junit-5) to Junit 5 `@ParameterizedTest`\n  * general [user guide](https://junit.org/junit5/docs/current/user-guide/)\n\n### Author\n[Serguei Kouzmine](kouzmine_serguei@yahoo.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergueik%2Fjunit-dataproviders","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergueik%2Fjunit-dataproviders","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergueik%2Fjunit-dataproviders/lists"}