所以我认为下面的代码可以在 TestNG 中正常运行,尽管它不能:
public class Tests {
int i = 0;
@Test
public void testA() {
Assert.assertEquals(0, i);
++i;
}
@Test
public void testB() {
Assert.assertEquals(0, i);
++i;
}
}
有没有办法让 TestNG 为每个测试方法启动一个新的测试类?
最佳答案
常见的解决方案是使用@BeforeMethod 方法来设置测试状态,
@BeforeMethod
public void setup() {
i = 0;
}
关于java - 使用 TestNG 让每个测试方法在其自己的测试类实例中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5842284/