Run method before each test

java, testing, testng

Solution

Annotate `init()` with `@BeforeMethod` annotation. See http://testng.org/doc/documentation-main.html#annotations

Problem

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?

Original source