Thursday, March 10, 2016

TestNg: @BeforeTest

@BeforeTest



BeforeTest execution = No of times you have defines <test name>.Below example you have used <test name> twice therefore Beforetest excutes twice













import org.testng.annotations.*;

public class testng_annotations {
   
    @BeforeSuite
    public void Beforesuite(){
        System.out.println("beforesuite");       
    }
   
    @BeforeTest
    public void Beforetest(){
        System.out.println("beforetest");
    }
   
    @DataProvider
    public Object[][] dataprovider(){
        Object[][] obj=new Object[2][2];
        obj[0][0]=1;
        obj[1][0]=2;
        obj[0][1]=3;
        obj[1][1]=4;
        return obj;
    }
   
    @Test(dataProvider="dataprovider")
    public void test(int i,int y) {   
            System.out.println("Data " + i+y);// execute 2nd       
    }
}

 

 Result

 

No comments:

Post a Comment