Making each test method run in its own instance of a test class with TestNG?
So I thought the following code would run fine in TestNG, although it doesn't:
public class Tests {
int i = 0;
@Test
public void testA() {
Assert.assertEquals(0, i);
++i;
}
@Test
public void testB() {
Assert.assertEquals(0, i);
++i;
}
}
Is there a way to make TestNG fire up a new Tests class for each test method?
常见的解决方案是使用@BeforeMethod方法来设置测试状态,
@BeforeMethod
public void setup() {
i = 0;
}
链接地址: http://www.djcxy.com/p/52242.html