01: package test.configuration;
02:
03: import java.util.ArrayList;
04: import java.util.Arrays;
05: import java.util.List;
06:
07: import org.testng.Assert;
08: import org.testng.Reporter;
09: import org.testng.TestListenerAdapter;
10: import org.testng.TestNG;
11: import org.testng.annotations.BeforeSuite;
12: import org.testng.annotations.Test;
13: import org.testng.xml.XmlClass;
14: import org.testng.xml.XmlSuite;
15: import org.testng.xml.XmlTest;
16:
17: import test.TestHelper;
18:
19: public class BeforeTestOrderingTest {
20: private static List<String> m_testNames;
21:
22: @BeforeSuite
23: public void init() {
24: m_testNames = new ArrayList<String>();
25: }
26:
27: static void addTest(String testName) {
28: m_testNames.add(testName);
29: }
30:
31: @Test
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(
40: "test.configuration.BeforeTestOrdering1Test");
41: t1.getXmlClasses().add(c1);
42:
43: XmlTest t2 = new XmlTest(s);
44: XmlClass c2 = new XmlClass(
45: "test.configuration.BeforeTestOrdering2Test");
46: t2.getXmlClasses().add(c2);
47:
48: TestNG tng = TestHelper.createTestNG();
49: TestListenerAdapter tl = new TestListenerAdapter();
50: tng.addListener(tl);
51: tng.setXmlSuites(Arrays.asList(new XmlSuite[] { s }));
52: tng.run();
53:
54: List<String> expected = Arrays.asList(new String[] { "bt1",
55: "f1", "at1", "bt2", "f2", "at2", });
56:
57: Assert.assertEquals(expected, m_testNames);
58: }
59:
60: private static void ppp(String s) {
61: System.out.println("[BeforeTestOrderingTest] " + s);
62: }
63:
64: }
|