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

上一篇: Zend Framework应用程序中的事件

下一篇: 使用TestNG让每个测试方法都在其自己的测试类实例中运行?