test

@RunWith(JUnitParamsRunner.class) public class ParamTest { @Test @FileParameters("src/test/resources/param.csv") public void test(int size, String[] arr) { assertEquals(size, arr.length); } } 

and the file from which to read:

 2, asdf, asdf 

in this case, the code works, it reads value 2 as int. other values ​​fall into the array of strings.

Change the arguments and order of values ​​in the file

 @RunWith(JUnitParamsRunner.class) public class ParamTest { @Test @FileParameters("src/test/resources/param.csv") public void test(String[] arr, int size) { assertEquals(size, arr.length); } } 

File:

 "asdf, asdf", 2 

We divide according to the csv file format in quotes a single field, the code gives an error

 java.lang.IllegalArgumentException: wrong number of arguments 

Those. as far as I understand, if a primitive goes, and then an array, then all the values ​​up to the end of the file to parse into this array, if, on the contrary, you cannot specify where the array ends in the file or the JunitParams functionality does not allow this?

    1 answer 1

    Those. as far as I understand, then if a primitive goes, and then an array, then all the values ​​until the end of the file are parsed into this array, but on the contrary, it is impossible to indicate where the array ends in the file

    Exactly.

    or JunitParams functionality does not allow this?

    Allows, but only when using the method as a data source. In the case of CSV this is not possible.

    Actually there are two possible solutions:

    1. Do without JUnitParams: parse CSV by yourself, applying the data reading rules you need. An example can be found here .
    2. Use method as a data source. Example from documentation :

       public Object mixedParameters() { boolean booleanValue = true; int[] primitiveArray = {1, 2, 3}; String stringValue = "Test"; String[] stringArray = {"one", "two", null}; return $( $(booleanValue, primitiveArray, stringValue, stringArray) ); } @Test @Parameters(method = "mixedParameters") @TestCaseName("{0}, {1}, {2}, {3}") public void usageOfMultipleTypesOfParameters( boolean booleanValue, int[] primitiveArray, String stringValue, String[] stringArray) { }