Hi TestNG team,
I was under the impression that when groups are used, the test will be run, one group at a time, and the @BeforeGroups will be run before executing the first test of the group and @AfterGroups will be run after the last test of the group before moving on to the next group. But when I tried an example, this doesn't seem to be the case. Groups are not considered when running and tests seemed to be running in the defined order. The @BeforeGroups is executed before the first test of the group is executed and @AfterGroup is run after the last test of the group.
Could you please help me understand the @BeforeGroups/@AfterGroups execution logic?
Example:
@BeforeGroups("g1")
public void doBeforeGroupsG1() {
System.out.println("testClass1: before groups g1");
}
@BeforeGroups("g2")
public void doBeforeGroupsG2() {
System.out.println("testClass1: before groups g2");
}
@Test(groups = {"g1"})
public void test1() {
System.out.println("testClass1: test1->g1");
}
@Test(groups = {"g2"})
public void test2() {
System.out.println("testClass1: test2->g2");
}
@Test(groups = {"g1"})
public void test3() {
System.out.println("testClass1: test3->g1");
}
@Test(groups = {"g2"})
public void test4() {
System.out.println("testClass1: test4->g2");
}
@AfterGroups("g2")
public void doAfterGroupsG2() {
System.out.println("testClass1: after groups g2");
}
@AfterGroups("g1")
public void doAfterGroupsG1() {
System.out.println("testClass1: after groups g1");
}
Expected order of execution:
doBeforeGroupsG1
test1
test3
doAfterGroupsG1
test2
test4
doAfterGroupsG2
Actual order of execution:
doBeforeGroupsG1
test1
doBeforeGroupsG2
test2
test3
doAfterGroupsG1
test4
doAfterGroupsG2
Thanks
Asma