• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package test.configuration;
2 
3 import org.testng.Assert;
4 import org.testng.Reporter;
5 import org.testng.TestListenerAdapter;
6 import org.testng.TestNG;
7 import org.testng.annotations.BeforeSuite;
8 import org.testng.annotations.Test;
9 import org.testng.xml.XmlClass;
10 import org.testng.xml.XmlSuite;
11 import org.testng.xml.XmlTest;
12 
13 import test.TestHelper;
14 
15 import java.util.ArrayList;
16 import java.util.Arrays;
17 import java.util.List;
18 
19 public class BeforeTestOrderingTest {
20   private static List<String> m_testNames;
21 
22   @BeforeSuite
init()23   public void init() {
24     m_testNames = new ArrayList<>();
25   }
26 
addTest(String testName)27   static void addTest(String testName) {
28     m_testNames.add(testName);
29   }
30 
31   @Test
verifyBeforeTestOrdering()32   public void verifyBeforeTestOrdering() {
33 
34     XmlSuite s = new XmlSuite();
35 
36     Reporter.log("BEFORE");
37 
38     XmlTest t1 = new XmlTest(s);
39     XmlClass c1 = new XmlClass("test.configuration.BeforeTestOrdering1Test");
40     t1.getXmlClasses().add(c1);
41 
42     XmlTest t2 = new XmlTest(s);
43     XmlClass c2 = new XmlClass("test.configuration.BeforeTestOrdering2Test");
44     t2.getXmlClasses().add(c2);
45 
46     TestNG tng = TestHelper.createTestNG();
47     TestListenerAdapter tl = new TestListenerAdapter();
48     tng.addListener(tl);
49     tng.setXmlSuites(Arrays.asList(new XmlSuite[] { s }));
50     tng.run();
51 
52     List<String> expected = Arrays.asList(new String[] {
53       "bt1", "f1", "at1", "bt2", "f2", "at2",
54     });
55 
56     Assert.assertEquals(expected, m_testNames);
57   }
58 
59 
60 
ppp(String s)61   private static void ppp(String s) {
62     System.out.println("[BeforeTestOrderingTest] " + s);
63   }
64 
65 }
66