I have a single jUnit4 test case with many variables. I read these variables from an external csv file. What I would like to have is that the test would run once for each line of input parameters from the file. I reckon this can be done by using @Parametrized.
I am not sure how though...
Right now I have something like this...
@Test
...
readFromCSV(filename);
String carName = varFromFile[0];
selectItemFromList(fieldName, carName);
The carName is a record in the csv file. How should I change this to have several entries for the carName taken from the file and one test ran for each one?
EDIT: Two more things. the read from file looks like this
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"), ';');
String [] nextValue;
String [] header = reader.readNext();
System.out.println(header[0] + " : " + header[1] + "etc...");
while ((nextValue = reader.readNext()) != null) {
System.out.println(nextValue[0] + " : " + nextValue[1] + "etc...");
}
The parametrized test...
@RunWith(value = Parameterized.class)
public class testParametrized {
private final TestParameters parameters;
public static class TestParameters {
String recId;
String carName;
}
public testParametrized(TestParameters parameters) {
this.parameters = parameters;
System.out.println(parameters);
}
@Parameters
public static Collection<Object[]> data() throws Exception {
Object[][] data = new Object[][] {
{ new TestParameters() },
{ new TestParameters() }
};
return Arrays.asList(data);
}
@Test
public void pushTest() {
System.out.println("Parameters : " + parameters);
}
}
How do I connect the two to have a test that takes parameters from csv file ?