在每次测试之前运行方法

St.*_*rio 0 java testing testng

testng 6.11在以下测试类中使用和编写测试:

public class MyTest{

    public int i;

    public void init(){
        //initialize i
    }

    @Test
    public void test1(){
        //test some
    }

    @Test
    public void test2(){
        //Here I need fresh value of i as it would be
        //right after invocation of init()
        //...
        //test something else
    }
}
Run Code Online (Sandbox Code Playgroud)

是否可以init()在调用测试类中的每个测试之前使 testng run方法?

Mic*_*ael 5

用注释init()进行@BeforeMethod注释。请参阅http://testng.org/doc/documentation-main.html#annotations