Skip to content

Commit

Permalink
Add test case for testng-team#689
Browse files Browse the repository at this point in the history
  • Loading branch information
juherr committed Jul 17, 2016
1 parent 13d29c2 commit 375d16e
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
66 changes: 48 additions & 18 deletions src/test/java/test/groupinvocation/GroupSuiteTest.java
Expand Up @@ -2,39 +2,52 @@

import org.testng.TestListenerAdapter;
import org.testng.TestNG;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;

import test.SimpleBaseTest;

import java.io.File;
import java.util.Arrays;
import java.util.List;

/**
* Test that <suite> tags can have g.
*/
@Test
public class GroupSuiteTest extends SimpleBaseTest {

public void includeFromSuite0() {
runWithSuite(g(), g(), "a", "b", "c", "a2", "b2", "c2");
private static final File PARENT = new File(getPathToResource("groupinvocation"));

@DataProvider
private static Object[][] dp() {
return new Object[][]{{true}, {false}};
}

@Test(dataProvider = "dp")
public void includeFromSuite0(boolean withSuiteFiles) {
runWithSuite(withSuiteFiles, "a", "b", "c", "a2", "b2", "c2");
}

public void includeFromSuite1() {
runWithSuite(g("a"), g(), "a", "a2");
@Test(dataProvider = "dp")
public void includeFromSuite1(boolean withSuiteFiles) {
runWithSuite(withSuiteFiles, g("a"), g(), "a", "a2");
}

public void includeFromSuite2() {
runWithSuite(g("a", "b"), g(), "a", "b", "a2", "b2");

@Test(dataProvider = "dp")
public void includeFromSuite2(boolean withSuiteFiles) {
runWithSuite(withSuiteFiles, g("a", "b"), g(), "a", "b", "a2", "b2");
}

public void excludeFromSuite1() {
runWithSuite(g(), g("a"), "b", "c", "b2", "c2");
@Test(dataProvider = "dp")
public void excludeFromSuite1(boolean withSuiteFiles) {
runWithSuite(withSuiteFiles, g(), g("a"), "b", "c", "b2", "c2");
}

public void excludeFromSuite2() {
runWithSuite(g(), g("a", "b"), "c", "c2");
@Test(dataProvider = "dp")
public void excludeFromSuite2(boolean withSuiteFiles) {
runWithSuite(withSuiteFiles, g(), g("a", "b"), "c", "c2");
}

@Test(description = "Include in both suite and test")
Expand All @@ -47,23 +60,40 @@ public void excludeTestAndSuite2() {
runWithSuite(g("a", "b"), g(), g(), g("a"), "b", "b2");
}

private void runWithSuite(List<String> suiteGroups, List<String> excludedSuiteGroups,
private void runWithSuite(boolean withSuiteFiles, String... methods) {
runWithSuite(withSuiteFiles, g(), g(), g(), g(), methods);
}

private void runWithSuite(boolean withSuiteFiles, List<String> suiteGroups, List<String> excludedSuiteGroups,
String... methods) {
runWithSuite(suiteGroups, excludedSuiteGroups, g(), g(), methods);
runWithSuite(withSuiteFiles, suiteGroups, excludedSuiteGroups, g(), g(), methods);
}

private void runWithSuite(List<String> suiteGroups, List<String> excludedSuiteGroups,
List<String> testGroups, List<String> excludedTestGroups,
String... methods) {
runWithSuite(false, suiteGroups, excludedSuiteGroups, testGroups, excludedTestGroups, methods);
}

private void runWithSuite(boolean withSuiteFiles, List<String> suiteGroups, List<String> excludedSuiteGroups,
List<String> testGroups, List<String> excludedTestGroups,
String... methods) {
TestNG tng = create();

XmlSuite suite = createXmlSuite("Groups");
suite.setIncludedGroups(suiteGroups);
suite.setExcludedGroups(excludedSuiteGroups);

XmlTest test = createXmlTest(suite, "Groups-test", GroupSuiteSampleTest.class, GroupSuiteSampleTest2.class);
test.setIncludedGroups(testGroups);
test.setExcludedGroups(excludedTestGroups);
if (withSuiteFiles) {
suite.setSuiteFiles(Arrays.asList(
new File(PARENT, "suiteA.xml").getAbsolutePath(),
new File(PARENT, "suiteB.xml").getAbsolutePath())
);
createXmlTest(suite, "Groups-test");
} else {
XmlTest test = createXmlTest(suite, "Groups-test", GroupSuiteSampleTest.class, GroupSuiteSampleTest2.class);
test.setIncludedGroups(testGroups);
test.setExcludedGroups(excludedTestGroups);
}

tng.setXmlSuites(Arrays.asList(suite));

Expand Down
8 changes: 8 additions & 0 deletions src/test/resources/groupinvocation/suiteA.xml
@@ -0,0 +1,8 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite A">
<test name="Test A">
<classes>
<class name="test.groupinvocation.GroupSuiteSampleTest" />
</classes>
</test>
</suite>
8 changes: 8 additions & 0 deletions src/test/resources/groupinvocation/suiteB.xml
@@ -0,0 +1,8 @@
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite B">
<test name="Test B">
<classes>
<class name="test.groupinvocation.GroupSuiteSampleTest2" />
</classes>
</test>
</suite>

0 comments on commit 375d16e

Please sign in to comment.