1package test.groupinvocation;
2
3import org.testng.TestListenerAdapter;
4import org.testng.TestNG;
5import org.testng.annotations.Test;
6import org.testng.xml.XmlSuite;
7import org.testng.xml.XmlTest;
8
9import test.SimpleBaseTest;
10
11import java.util.Arrays;
12
13/**
14 * Test that <suite> tags can have groups.
15 */
16@Test
17public class GroupSuiteTest extends SimpleBaseTest {
18
19  public void includeFromSuite0() {
20    runWithSuite(g(), g(), g("a", "b", "c"));
21  }
22
23  public void includeFromSuite1() {
24    runWithSuite(g("a"), g(), g("a"));
25  }
26
27  public void includeFromSuite2() {
28    runWithSuite(g("a", "b"), g(), g("a", "b"));
29  }
30
31  public void excludeFromSuite1() {
32    runWithSuite(g(), g("a"), g("b", "c"));
33  }
34
35  public void excludeFromSuite2() {
36    runWithSuite(g(), g("a", "b"), g("c"));
37  }
38
39  @Test(description = "Include in both suite and test")
40  public void includeTestAndSuite1() {
41    runWithSuite(g("a"), g(), g("b"), g(), g("a", "b"));
42  }
43
44  @Test(description = "Include in suite, exclude in test")
45  public void excludeTestAndSuite2() {
46    runWithSuite(g(), g("a"), g(), g("a"), g("b", "c"));
47  }
48
49  private void runWithSuite(String[] suiteGroups, String[] excludedSuiteGroups,
50      String[] methods) {
51    runWithSuite(suiteGroups, excludedSuiteGroups, g(), g(), methods);
52  }
53
54  private void runWithSuite(String[] suiteGroups, String[] excludedSuiteGroups,
55      String[] testGroups, String[] excludedTestGroups,
56      String[] methods) {
57    XmlSuite s = createXmlSuite("Groups");
58    s.setIncludedGroups(Arrays.asList(suiteGroups));
59    s.setExcludedGroups(Arrays.asList(excludedSuiteGroups));
60    XmlTest t = createXmlTest(s, "Groups-test", GroupSuiteSampleTest.class.getName());
61    t.setIncludedGroups(Arrays.asList(testGroups));
62    t.setExcludedGroups(Arrays.asList(excludedTestGroups));
63    TestListenerAdapter tla = new TestListenerAdapter();
64    TestNG tng = create();
65    tng.addListener(tla);
66    tng.setXmlSuites(Arrays.asList(new XmlSuite[] { s }));
67    tng.run();
68
69    verifyPassedTests(tla, methods);
70  }
71
72  private String[] g(String... groups) {
73    return groups;
74  }
75}
76