我正在编写一个 JUnit 测试用例。我想初始化一个列表对象。为简洁起见,让我们初始化一个String对象列表:
public class MyTest {
@Rule
public List<MySQLContainer> tests = Arrays.asList(new MySQLContainer("5.5"), new MySQLContainer("5.6"));
@Test
public void myTest() {
}
}
执行时,我收到以下运行时错误:
org.junit.internal.runners.rules.ValidationError: The @Rule 'tests' must implement MethodRule or TestRule.
at org.junit.internal.runners.rules.RuleMemberValidator$FieldMustBeARule.validate(RuleMemberValidator.java:234)
at org.junit.internal.runners.rules.RuleMemberValidator.validateMember(RuleMemberValidator.java:99)
at org.junit.internal.runners.rules.RuleMemberValidator.validate(RuleMemberValidator.java:93)
at org.junit.runners.BlockJUnit4ClassRunner.validateFields(BlockJUnit4ClassRunner.java:196)
at org.junit.runners.BlockJUnit4ClassRunner.collectInitializationErrors(BlockJUnit4ClassRunner.java:1
当我简单地初始化 aMySQLContainer而不是List<MySQLContainer>.
为什么这不起作用?我该如何解决?
我的依赖项中有 JUnit 4.12。
撒科打诨
MMMHUHU
月关宝盒
相关分类