3 回答

TA贡献1934条经验 获得超2个赞
@Rules 用于在每个测试方法之前执行代码。如果你只需要初始化一个成员,把这个初始化放在一个用@Before以下注释的方法中:
public class MyTest {
private List<MySQLContainer> containers;
@Before
public void initContainers() {
containers = = Arrays.asList(new MySQLContainer("5.5"), new MySQLContainer("5.6"));
}
@Test
public void myTest() {
// Some test...
}
}

TA贡献1772条经验 获得超5个赞
删除@Rule,一切都很好。
public class MyTest {
private final List<MySQLContainer> tests = Arrays.asList(
new MySQLContainer("5.5"),
new MySQLContainer("5.6")
);
@Test
public void myTest() {
}
}
@Rule 用于 JUnit 4 扩展,可以做一些更复杂的事情。
添加回答
举报