I would like to write JUnit 5 parametrized test which takes string array (String[]
) as a parameter:
@ParameterizedTest
@MethodSource("stringArrayProvider")
void parseFirstAndSecondInt(String[] args) {
Arguments arguments = new Arguments(args);
assertEquals(1, arguments.getFirst());
assertEquals(2, arguments.getSecond());
}
I'm not sure, how to provide a collection/stream/iterator of string arrays. I've unsuccessfully tried following approach with @MethodSource
annotation
static Stream<String[]> stringArrayProvider() {
return Stream.of(
new String[]{"1", "2"},
new String[]{"1", "2", "3"});
}
but I'm receiving this exception:
org.junit.jupiter.params.converter.ArgumentConversionException:
No implicit conversion to convert object of type java.lang.String to type [Ljava.lang.String;
What would be a good design/solution to have such kind of parameterized test?