Skip to content

Commit

Permalink
After methods should be skipped when exclusion used
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
krmahadevan committed Oct 14, 2017
1 parent f4a6eb4 commit de2936f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Current
Fixed: GITHUB-1574: Before/After methods are not running when groups "include" in suite (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)
Fixed: GITHUB-1566: Invalid XML characters in Params in testng-results.xml (Krishnan Mahadevan)
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/testng/internal/XmlMethodSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ private static boolean isIncluded(Collection<String> includedGroups, boolean noG
}

private static boolean isExcluded(Collection<String> excludedGroups, String... groups) {
boolean noGroups = (groups == null || groups.length == 0);
if (!excludedGroups.isEmpty() && noGroups) {
return true;
}
return isMemberOf(excludedGroups, groups);
}

Expand Down
13 changes: 12 additions & 1 deletion src/test/java/test/groupinvocation/GroupSuiteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,7 +124,7 @@ private void runWithSuite(String[] withSuiteFiles, boolean groupsWithXml, List<S
test.setExcludedGroups(excludedTestGroups);
}

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

InvokedMethodNameListener listener = new InvokedMethodNameListener();
tng.addListener((ITestNGListener) listener);
Expand All @@ -133,6 +134,16 @@ private void runWithSuite(String[] withSuiteFiles, boolean groupsWithXml, List<S
assertThat(listener.getInvokedMethodNames()).containsExactly(methods);
}

@Test(description = "GITHUB-1574")
public void testToCheckNoConfigurationsAreExecuted() {
XmlSuite suite = createXmlSuite("suite");
XmlTest test = createXmlTest(suite, "test", Issue1574TestclassSample.class);
test.addExcludedGroup("sometest");
TestNG testng = create(suite);
testng.run();
assertThat(Issue1574TestclassSample.messages).containsExactly("anothertest","@AfterSuite");
}

private static List<String> g(String... groups) {
return Arrays.asList(groups);
}
Expand Down

0 comments on commit de2936f

Please sign in to comment.