Pragmatists/JUnitParams

Specifically setting delimiter

seppaleinen opened this issue · 1 comments

I would love to be able to specifically set the delimiter to be used in the @parameters annotation, so that I would be able to input strings with commas in them.

Kind of like with the awk -F'|' command

I'm thinking somewhere along the lines of this example

	@Test
	@Parameters({"hello, goodmorning|goodnight"}, delimiter="|")
	public void test(String str, String str2) {
		System.out.println(str + ":" + str2);
	}

I'm open to there being reasons for this being a bad idea, or that I've missed something :)

We will not introduce such change for couple of reasons. The most important is that @Parameters annotation abstraction supports many types of "source" of parameters - you can provide parameters by String, method or csv file (using source + provider). So it's too general to introduce it there.

It's easy to make it work by providing params with method e.g.

    @Test
    @Parameters(method = "paramsByPipe")
    public void byPipe(String parameter) {
        System.out.println("parameter: " + parameter);
    }

    @Test
    @Parameters(method = "paramsByComma")
    public void byComma(String parameter) {
        System.out.println("parameter: " + parameter);
    }

    public List<String> paramsByPipe() {
        return splitBy("hello, goodmorning|goodnight", "\\|");
    }

    public List<String> paramsByComma() {
        return splitBy("hello, goodmorning|goodnight", ",");
    }

    private ArrayList<String> splitBy(String params, String splitter) {
        return Lists.newArrayList(params.split(splitter));
    }