我想实现以下场景。从传递给我的类中应该并行运行的第一个测试的参数列表开始,然后我想切换到传递给第一个测试的非常单个参数的顺序行为。给定以下代码:
public class TrickyTestExecutionOrder {
@Test
@ArgumentsSource(CustomArgumentProvider.class)
public void firstParallelForEachNumber(String number) {
...
}
@Nested
public class ForEveryArgumentProceededInFirstTestMethod {
@Test
public void thenDoThis() {
...
}
@Test
public void andDoThat() {
...
}
@Test
public void andFinallyThisAgain() {
...
}
}
}
没有必要使用 ArgumentsProvider 作为参数提供者。@MethodSource 或 ParameterResolver 是满足要求的其他选项。但是,目前我正在使用参数提供程序类:
public static class CustomArgumentProvider implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) throws Exception {
return Stream.of(
Arguments.of("12345"),
Arguments.of("67890")
);
}
}
执行路径应该如下:
Thread-1 Thread-2
firstParallelForEachNumber: "12345" "67890"
| |
| |
ForEveryArgumentProceededInFirstTestMethod : thenDoThis thenDoThis
| |
andDoThat andDoThat
| |
andFinallyThisAgain andFinallyThisAgain
JUnit5可以做到这一点吗?