Im using testng 6.11
and writing tests in the following test class:
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
}
}
Is it possible to make testng run init()
method before invocation of each test in a test class?
Annotate init()
with @BeforeMethod
annotation. See http://testng.org/doc/documentation-main.html#annotations
Sure, your can use the annotation for that
@BeforeTest: The annotated method will be run before any test method belonging to the classes inside the tag is run.
You can use @BeforeMethod
annotatation to execute any method before every test.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.