【发布时间】:2020-01-27 10:46:42
【问题描述】:
我有一个测试用例,我以枚举的形式提供了我的测试数据。喜欢
enum TestTransactions {
TestTransactions(Transaction T1, Transaction T2, String expectedOutput){}
}
在我的测试类中,我必须将其用作:
class Test {
private final static int REPETITION_COUNT = TestTransactions.values().length;
@RepeatedTest(value=REPETITION_COUNT)
private void testAllTransactions(RepetitionInfo info) {
TestTransactions currentTest = TestTransactions.values()[info.getCurrentRepetition()];
logger.info("Executing test for " + currentTest.name());
setExpectationsFor(currentTest);
whenControllerIsCalled();
Assert.assertEquals(currentTest.getExpectedOutput(), result.getBody());
}
}
这行@RepeatedTest(value=REPETITION_COUNT) 给出了编译错误,提示“属性值必须是常量。”
有什么方法可以实现吗?虽然我已经尝试在构造函数和静态块内以及在声明期间分配REPETITION_COUNT (declared as final),如本例所示。
【问题讨论】:
标签: java annotations repeat junit5