I have a problem with testNG @beforeGroups annotations. I tried to create a simple example to check the order in which the annotations are executed. My problem is that I cannot get beforeGroups (and afterGroups) to occur.
My code:
OrderTest.java
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class OrderTest {
@BeforeSuite
public void beforeSuite() {
System.out.println("1. Before Suite");
}
@BeforeTest
public void beforeTest() {
System.out.println("2. Before Test");
}
@BeforeGroups(groups = "group1")
public void beforeGroups1() {
System.out.println("3. Before Groups");
}
@BeforeClass
public void beforeClass() {
System.out.println("4. Before Class");
}
@BeforeMethod
public void beforeMethod() {
System.out.println("5. Before Method");
}
@Test(groups= "group1")
public void test1() {
System.out.println("Test 1");
}
@Test(groups = {"group2"})
public void test2() {
System.out.println("Test 2");
}
@Test
public void test3() {
System.out.println("Test 3");
}
@Test
public void test4() {
System.out.println("Test 4");
}
@Test
public void test5() {
System.out.println("Test 5");
}
@AfterMethod
public void afterMethod() {
System.out.println("7. After Method");
}
@AfterClass
public void afterClass() {
System.out.println("8. After Class");
}
@AfterGroups(groups="Group1")
public void afterGroups1() {
System.out.println("9. After Groups1");
}
@AfterTest
public void afterTest() {
System.out.println("10. After Test");
}
@AfterSuite
public void afterSuite() {
System.out.println("11. afterSuite");
}
}
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="package.OrderTest"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
Results I'm getting
[RemoteTestNG] detected TestNG version 7.3.0
1. Before Suite
2. Before Test
4. Before Class
5. Before Method
Test 1
7. After Method
5. Before Method
Test 2
7. After Method
5. Before Method
Test 3
7. After Method
5. Before Method
Test 4
7. After Method
5. Before Method
Test 5
7. After Method
8. After Class
10. After Test
11. afterSuite
My question is, is there an way to make beforeGroups to happen?
Aucun commentaire:
Enregistrer un commentaire