diff --git a/testng-core/src/test/java/test/cli/github2974/OverrideGroupsCliTest.java b/testng-core/src/test/java/test/cli/github2974/OverrideGroupsCliTest.java new file mode 100644 index 0000000000..3cca8d0850 --- /dev/null +++ b/testng-core/src/test/java/test/cli/github2974/OverrideGroupsCliTest.java @@ -0,0 +1,27 @@ +package test.cli.github2974; + +import java.util.List; +import org.testng.Assert; +import org.testng.CommandLineArgs; +import org.testng.TestNG; +import org.testng.annotations.Test; +import test.SimpleBaseTest; + +public class OverrideGroupsCliTest extends SimpleBaseTest { + + @Test(description = "GITHUB-2974") + public void overrideGroupsFromCliInParentChildXml() { + TestNG testNG = + new TestNG(false) { + { + CommandLineArgs args = new CommandLineArgs(); + args.groups = "override_group"; + args.suiteFiles = List.of(getPathToResource("2974/parent.xml")); + configure(args); + } + }; + testNG.run(); + Assert.assertTrue(TwoGroupsTest.NAMES.contains("must run")); + Assert.assertFalse(TwoGroupsTest.NAMES.contains("must not run")); + } +} diff --git a/testng-core/src/test/java/test/cli/github2974/TwoGroupsTest.java b/testng-core/src/test/java/test/cli/github2974/TwoGroupsTest.java new file mode 100644 index 0000000000..09aa199a8d --- /dev/null +++ b/testng-core/src/test/java/test/cli/github2974/TwoGroupsTest.java @@ -0,0 +1,20 @@ +package test.cli.github2974; + +import java.util.ArrayList; +import java.util.List; +import org.testng.annotations.Test; + +public class TwoGroupsTest { + + public static final List NAMES = new ArrayList<>(); + + @Test(groups = {"override_group"}) + public void test1() { + NAMES.add("must run"); + } + + @Test(groups = {"default_group"}) + public void test2() { + NAMES.add("must not run"); + } +} diff --git a/testng-core/src/test/resources/2974/child.xml b/testng-core/src/test/resources/2974/child.xml new file mode 100644 index 0000000000..ece3a45a08 --- /dev/null +++ b/testng-core/src/test/resources/2974/child.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/testng-core/src/test/resources/2974/parent.xml b/testng-core/src/test/resources/2974/parent.xml new file mode 100644 index 0000000000..66e092208b --- /dev/null +++ b/testng-core/src/test/resources/2974/parent.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/testng-core/src/test/resources/testng.xml b/testng-core/src/test/resources/testng.xml index 7013764a22..4e3103d835 100644 --- a/testng-core/src/test/resources/testng.xml +++ b/testng-core/src/test/resources/testng.xml @@ -109,6 +109,7 @@ +