Reputation: 27375
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?
Upvotes: 2
Views: 8963
Reputation: 3078
You can use @BeforeMethod
annotatation to execute any method before every test.
Upvotes: 0
Reputation: 623
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.
Upvotes: 0
Reputation: 1467
Annotate init()
with @BeforeMethod
annotation. See http://testng.org/doc/documentation-main.html#annotations
Upvotes: 6