From 324bb80a5ce784270d6e3183f99654718bf84acb Mon Sep 17 00:00:00 2001 From: Krishnan Mahadevan Date: Sat, 14 Oct 2017 14:31:43 +0530 Subject: [PATCH] After methods should be skipped when exclusion used MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1574 Suppose there are one or more configuration methods which don’t belong to any group and for which “alwaysRun” attribute is not set, and when the user specifies a valid exclusion list for groups, TestNG would still execute those configuration methods. Fixed this anomaly. --- CHANGES.txt | 1 + .../testng/internal/XmlMethodSelector.java | 3 ++ .../test/groupinvocation/GroupSuiteTest.java | 15 ++++++- .../Issue1574TestclassSample.java | 43 +++++++++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/test/java/test/groupinvocation/Issue1574TestclassSample.java diff --git a/CHANGES.txt b/CHANGES.txt index 315b0ad025..35e4717b4c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ Current +Fixed: GITHUB-1574: Before/After methods are not running when groups "include" in suite (Krishnan Mahadevan) Fixed: GITHUB-217: exception in DataProvider doesn't fail test run (Krishnan Mahadevan) Fixed: GITHUB-987: Parameters threadCount and parallel doesn't work with maven (Krishnan Mahadevan) Fixed: GITHUB-1472: Optimize DynamicGraph.getUnfinishedNodes (Krishnan Mahadevan & Nathan Reynolds) diff --git a/src/main/java/org/testng/internal/XmlMethodSelector.java b/src/main/java/org/testng/internal/XmlMethodSelector.java index 2b9b80f979..7b083ebf9b 100644 --- a/src/main/java/org/testng/internal/XmlMethodSelector.java +++ b/src/main/java/org/testng/internal/XmlMethodSelector.java @@ -275,6 +275,9 @@ private static boolean isIncluded(Collection includedGroups, boolean noG } private static boolean isExcluded(Collection excludedGroups, String... groups) { + if (!excludedGroups.isEmpty() && groups.length == 0) { + return true; + } return isMemberOf(excludedGroups, groups); } diff --git a/src/test/java/test/groupinvocation/GroupSuiteTest.java b/src/test/java/test/groupinvocation/GroupSuiteTest.java index 551feaf4a7..2e854c630b 100644 --- a/src/test/java/test/groupinvocation/GroupSuiteTest.java +++ b/src/test/java/test/groupinvocation/GroupSuiteTest.java @@ -14,6 +14,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -123,7 +124,7 @@ private void runWithSuite(String[] withSuiteFiles, boolean groupsWithXml, List g(String... groups) { return Arrays.asList(groups); } diff --git a/src/test/java/test/groupinvocation/Issue1574TestclassSample.java b/src/test/java/test/groupinvocation/Issue1574TestclassSample.java new file mode 100644 index 0000000000..716d57a37d --- /dev/null +++ b/src/test/java/test/groupinvocation/Issue1574TestclassSample.java @@ -0,0 +1,43 @@ +package test.groupinvocation; + +import org.testng.annotations.AfterMethod; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class Issue1574TestclassSample { + @BeforeSuite + public void setupSuite() { + } + + @BeforeTest + public void setUpTest() { + } + + @BeforeMethod + public void setUpMethod() { + } + + @AfterMethod + public void tearDownMethod() { + } + + @AfterTest + public void tearDownTest() { + } + + @AfterSuite(alwaysRun = true) + public void tearDownSuite() { + } + + @Test(groups = {"sometest"}) + public void someTest() { + } + + @Test(groups = {"anothertest"}) + public void anothertest() { + } +}