Stack Exchange
JUnitParamsRunner with input file - string parameter issue
I want to move my JUnit test parameters to separate CSV file. I use JUnitParamsRunner like that:
@RunWith(JUnitParamsRunner.class)
public class TestClass {
...
@Test
    @FileParameters("src/test/resources/input.csv")
    public void testMethod(int assertResult, String inputMark) throws InterruptedException {
....

My CSV file is like that
2,"xxx"
2,"xxx"
2,"xxxx,xxx-1"
4,"xxxx xxxxx-xx"

When I run the test parameter "xxxx,xxx-1" gives me java error because of wrong number of arguments (I think because of comma inside). How can I pass string parameters with special symbols in CVS file in my scenario?

Provide your custom mapper to parse CSV data:
@RunWith(JUnitParamsRunner.class)
public class TestClass {

    @Test
    @FileParameters(value = "src/test/resources/input.csv", mapper = CustomMapper.class)
    public void testMethod(int assertResult, String inputMark) {}

    public static class CustomMapper extends IdentityMapper {
        @Override
        public Object[] map(Reader reader) {
            Object[] map = super.map(reader);
            List<Object> result = new LinkedList<Object>();
            for (Object lineObj : map) {
                String line = lineObj.toString();
                int index = line.indexOf(",");
                String arg1 = line.substring(0, index);
                String arg2 = line.substring(index + 1, line.length());
                result.add(new Object[] {arg1, arg2});
            }
            return result.toArray();
        }
    }
}

For more complex solution - you should use regexp in CustomMapper to properly parse CSV data.
