Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run method before each test

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?

like image 546
St.Antario Avatar asked Sep 20 '26 21:09

St.Antario


1 Answers

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

like image 83
Michael Avatar answered Sep 22 '26 09:09

Michael