• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package test.override;
2 
3 import org.testng.Assert;
4 import org.testng.TestListenerAdapter;
5 import org.testng.TestNG;
6 import org.testng.annotations.Test;
7 import org.testng.internal.Utils;
8 import org.xml.sax.SAXException;
9 
10 import test.SimpleBaseTest;
11 
12 import javax.xml.parsers.ParserConfigurationException;
13 
14 import java.io.File;
15 import java.io.IOException;
16 import java.util.Arrays;
17 
18 /**
19  * Verify that command line switches override parameters in testng.xml.
20  *
21  * @author Cedric Beust <cedric@beust.com>
22  */
23 public class OverrideTest extends SimpleBaseTest {
24 
runTest(String include, String exclude)25   private void runTest(String include, String exclude) {
26     File f = Utils.createTempFile(
27         "<suite name=\"S\">"
28         + "  <test name=\"T\">"
29         + "    <classes>"
30         + "      <class name=\"test.override.OverrideSampleTest\" />"
31         + "    </classes>"
32         + "  </test>"
33         + "</suite>"
34         );
35     TestNG tng = create();
36     TestListenerAdapter tla = new TestListenerAdapter();
37     tng.addListener(tla);
38     if (include != null) tng.setGroups(include);
39     if (exclude != null) tng.setExcludedGroups(exclude);
40     tng.setTestSuites(Arrays.asList(f.getAbsolutePath()));
41     tng.run();
42 
43     Assert.assertEquals(tla.getPassedTests().size(), 1);
44   }
45 
46   @Test(description = "Override -groups")
overrideIncludeShouldWork()47   public void overrideIncludeShouldWork()
48       throws ParserConfigurationException, SAXException, IOException {
49     runTest("goodGroup", null);
50   }
51 
52   @Test(description = "Override -excludegroups")
overrideExcludeShouldWork()53   public void overrideExcludeShouldWork()
54       throws ParserConfigurationException, SAXException, IOException {
55     runTest(null, "badGroup");
56   }
57 
58   @Test(description = "Override -groups and -excludegroups")
overrideIncludeAndExcludeShouldWork()59   public void overrideIncludeAndExcludeShouldWork()
60       throws ParserConfigurationException, SAXException, IOException {
61     runTest("goodGroup", "badGroup");
62   }
63 }
64