如何将多个并行流传递给 Junit5 参数化测试?
How to pass multiple parallel streams to Junit5 Parameterized test?
我有两个等长的 ArrayList<> 对象,我的 Junit5 参数化测试的语法为:
@ParamterizedTest
@MethodSource("dummyfunction");
void functionName(String s1, String s2)
{
.....
.....
}
private Stream<Arguments> dummyfunction()
{
ArrayList<String> arr1;
ArrayList<String> arr2;
.....
.....
return something;
}
如何 return 每个 ArrayList 中的元素,以便一个列表提供 s1 而另一个列表提供 s2 作为根据 functionName 函数?
打印的朴素解决方案
s1 = [1], s2 = [a]
s1 = [2], s2 = [b]
s1 = [3], s2 = [c]
使用以下实现
@ParameterizedTest
@MethodSource("dummyFunction")
void functionName(String s1, String s2) {
System.out.println("s1 = [" + s1 + "], s2 = [" + s2 + "]");
}
static Stream<Arguments> dummyFunction() {
List<String> list1 = List.of("1", "2", "3");
List<String> list2 = List.of("a", "b", "c");
Assertions.assertEquals(list1.size(), list2.size());
List<Arguments> arguments = new ArrayList<>();
for (int i = 0; i < list1.size(); i++) {
arguments.add(Arguments.of(list1.get(i), list2.get(i)));
}
return arguments.stream();
}
我有两个等长的 ArrayList<> 对象,我的 Junit5 参数化测试的语法为:
@ParamterizedTest
@MethodSource("dummyfunction");
void functionName(String s1, String s2)
{
.....
.....
}
private Stream<Arguments> dummyfunction()
{
ArrayList<String> arr1;
ArrayList<String> arr2;
.....
.....
return something;
}
如何 return 每个 ArrayList 中的元素,以便一个列表提供 s1 而另一个列表提供 s2 作为根据 functionName 函数?
打印的朴素解决方案
s1 = [1], s2 = [a]
s1 = [2], s2 = [b]
s1 = [3], s2 = [c]
使用以下实现
@ParameterizedTest
@MethodSource("dummyFunction")
void functionName(String s1, String s2) {
System.out.println("s1 = [" + s1 + "], s2 = [" + s2 + "]");
}
static Stream<Arguments> dummyFunction() {
List<String> list1 = List.of("1", "2", "3");
List<String> list2 = List.of("a", "b", "c");
Assertions.assertEquals(list1.size(), list2.size());
List<Arguments> arguments = new ArrayList<>();
for (int i = 0; i < list1.size(); i++) {
arguments.add(Arguments.of(list1.get(i), list2.get(i)));
}
return arguments.stream();
}