Skip to content

Commit

Permalink
testng-team#2974: Add tests for groups/excludedGroups cli parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
dr29abrt committed Sep 1, 2023
1 parent 91a003a commit 97dd348
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package test.cli.github2974;

import java.util.ArrayList;
import java.util.List;
import org.testng.Assert;
import org.testng.CommandLineArgs;
import org.testng.ITestListener;
import org.testng.ITestResult;
import org.testng.TestNG;
import org.testng.annotations.Test;
import test.SimpleBaseTest;

public class OverrideGroupsCliTest extends SimpleBaseTest {

private static class NameCollector implements ITestListener {
List<String> names = new ArrayList<>();

@Override
public void onTestSuccess(ITestResult result) {
names.add(result.getName());
}
}

@Test(description = "GITHUB-2974")
public void overrideIncludeGroupsFromCliInParentChildXml() {
TestNG testNG =
new TestNG(false) {
{
CommandLineArgs args = new CommandLineArgs();
args.groups = "override_group";
args.suiteFiles = List.of(getPathToResource("2974/parent_include.xml"));
configure(args);
}
};
NameCollector collector = new NameCollector();
testNG.addListener(collector);
testNG.run();
Assert.assertTrue(collector.names.contains("overrideTest"));
Assert.assertFalse(collector.names.contains("defaultTest"));
}

@Test(description = "GITHUB-2974")
public void overrideExcludeGroupsFromCliInParentChildXml() {
TestNG testNG =
new TestNG(false) {
{
CommandLineArgs args = new CommandLineArgs();
args.excludedGroups = "override_group";
args.suiteFiles = List.of(getPathToResource("2974/parent_exclude.xml"));
configure(args);
}
};
NameCollector collector = new NameCollector();
testNG.addListener(collector);
testNG.run();
Assert.assertTrue(collector.names.contains("defaultTest"));
Assert.assertFalse(collector.names.contains("overrideTest"));
}

}
12 changes: 12 additions & 0 deletions testng-core/src/test/java/test/cli/github2974/TwoGroupsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package test.cli.github2974;

import org.testng.annotations.Test;

public class TwoGroupsTest {

@Test(groups = "override_group")
public void overrideTest() {}

@Test(groups = "default_group")
public void defaultTest() {}
}
9 changes: 9 additions & 0 deletions testng-core/src/test/resources/2974/child.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="child">

<test name="Tests inherit groups from parent xml">
<classes>
<class name="test.cli.github2974.TwoGroupsTest"/>
</classes>
</test>
</suite>
12 changes: 12 additions & 0 deletions testng-core/src/test/resources/2974/parent_exclude.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="parent suite with default group" parallel="methods" thread-count="1">

<groups>
<run>
<exclude name="default_group"/>
</run>
</groups>
<suite-files>
<suite-file path="child.xml"/>
</suite-files>
</suite>
12 changes: 12 additions & 0 deletions testng-core/src/test/resources/2974/parent_include.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="parent suite with default group" parallel="methods" thread-count="1">

<groups>
<run>
<include name="default_group"/>
</run>
</groups>
<suite-files>
<suite-file path="child.xml"/>
</suite-files>
</suite>
1 change: 1 addition & 0 deletions testng-core/src/test/resources/testng.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<class name="test.github765.ExcludeSyntheticMethodsFromTemplateCallsTest"/>
<class name="test.github1405.TestExclusionOfMainMethod"/>
<class name="test.cli.CliTest"/>
<class name="test.cli.github2974.OverrideGroupsCliTest"/>
<class name="test.thread.ParallelSuiteTest"/>
<class name="test.simple.IncludedExcludedTest" />
<class name="test.reports.ReportTest" />
Expand Down

0 comments on commit 97dd348

Please sign in to comment.