我想重复执行以下测试类:
class Test {
static Foo foo;
@BeforeAll
static void setUpAll() {
foo = generateRandomFoo();
}
@ParameterizedTest
@ValueSource(ints = {1, 2, 3, 4})
void testBar(int i) {
assertThat(foo.bar(i))
.hasSize(i);
}
@ParameterizedTest
@ValueSource(ints = {1, 2, 3, 4})
void testQux(int i) {
assertThat(foo.qux(i))
.contains(i);
}
}
我尝试@ParameterizedTest
在方法上同时使用注释和@RepeatedTest
,但它们无法一起使用。即使可以,它仍然无法满足我的要求,因为我需要在重复之间初始化foo
in setUpAll
,而参数化调用应该在重复内进行( 的值相同foo
)。
以下是我需要的:
- 重复1:
- 初始化
foo
setUpAll
testBar
使用参数 1..4执行testQux
使用参数 1..4执行
- 初始化
- 重复2:
- 初始化
foo
setUpAll
testBar
使用参数 1..4执行testQux
使用参数 1..4执行
- 初始化
- ETC。
有没有办法在 JUnit 5(Jupiter)中做到这一点?