我想编写JUnit 5参数化测试,它将字符串数组(String[])作为参数:
@ParameterizedTest
@MethodSource("stringArrayProvider")
void parseFirstAndSecondInt(String[] args) {
Arguments arguments = new Arguments(args);
assertEquals(1, arguments.getFirst());
assertEquals(2, arguments.getSecond());
}
Run Code Online (Sandbox Code Playgroud)
我不确定,如何提供字符串数组的集合/流/迭代器.我没有成功尝试使用@MethodSource注释方法
static Stream<String[]> stringArrayProvider() {
return Stream.of(
new String[]{"1", "2"},
new String[]{"1", "2", "3"});
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个例外:
org.junit.jupiter.params.converter.ArgumentConversionException:
No implicit conversion to convert object of type java.lang.String to type [Ljava.lang.String;
Run Code Online (Sandbox Code Playgroud)
有这种参数化测试的好设计/解决方案是什么?