[英]Run method before each test
我正在使用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
}
}
是否有可能在調用測試類中的每個測試之前使testng運行init()
方法?
用@BeforeMethod
注解注釋init()
。 參見http://testng.org/doc/documentation-main.html#annotations
當然,您可以為此使用注釋
@BeforeTest:帶注釋的方法將在運行屬於該標記內的類的任何測試方法之前運行。
您可以使用@BeforeMethod
注釋在每次測試之前執行任何方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.