I am using the @Factory annotation of TestNG with @dataProvider method in @BeforeClass level .
And expecting First iteration of @beforeclass method is executed then both the @Test method should executed for same iteration and so on ....
But observed that after @BeforeClass method execution , 1st @Test method is executed and once these execution is completed, 2nd @Test method is executed
Not sure what is the issue ?
public class TestPrackties {
String userMode;
@Factory(dataProvider = "userModeProvider")
public TestPrackties(String userMode) {
this.userMode = userMode;
}
@BeforeClass(alwaysRun = true)
public void init() throws Exception {
System.out.println("Before Running the class userMode is " + userMode);
}
@Test(groups = "testFactory", description = "test method1")
public void testMethod1() throws Exception {
System.out.println("Inside method 1 " + userMode );
}
@Test(groups = "testFactory", description = "test method2")
public void testMethod2() throws Exception {
System.out.println("Inside method 2 " + userMode);
}
@DataProvider
private static String [][] userModeProvider() {
return new String [][]{
new String []{"Admin"},
new String []{"Tenant"},
new String []{"AdminUser"},
new String []{"TenantUser"},
};
}
}
----------------------------------------------
Actual OutPut :-
Before Running the class userMode is Tenant
Inside method 1 Tenant
Before Running the class userMode is TenantUser
Inside method 1 TenantUser
Before Running the class userMode is AdminUser
Inside method 1 AdminUser
Before Running the class userMode is Admin
Inside method 1 Admin
Inside method 2 Tenant
Inside method 2 TenantUser
Inside method 2 AdminUser
Inside method 2 Admin
--------------------------------------------------------
Expected Output :-
Before Running the class userMode is Tenant
Inside method 1 Tenant
Inside method 2 Tenant
Before Running the class userMode is TenantUser
Inside method 1 TenantUser
Inside method 2 TenantUser
Before Running the class userMode is AdminUser
Inside method 1 AdminUser
Inside method 2 AdminUser
Before Running the class userMode is Admin
Inside method 1 Admin
Inside method 2 Admin