Skip to content

Commit de2936f

Browse files
committed
After methods should be skipped when exclusion used
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.
1 parent f4a6eb4 commit de2936f

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Current
2+
Fixed: GITHUB-1574: Before/After methods are not running when groups "include" in suite (Krishnan Mahadevan)
23
Fixed: GITHUB-987: Parameters threadCount and parallel doesn't work with maven (Krishnan Mahadevan)
34
Fixed: GITHUB-1472: Optimize DynamicGraph.getUnfinishedNodes (Krishnan Mahadevan & Nathan Reynolds)
45
Fixed: GITHUB-1566: Invalid XML characters in Params in testng-results.xml (Krishnan Mahadevan)

src/main/java/org/testng/internal/XmlMethodSelector.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@ private static boolean isIncluded(Collection<String> includedGroups, boolean noG
275275
}
276276

277277
private static boolean isExcluded(Collection<String> excludedGroups, String... groups) {
278+
boolean noGroups = (groups == null || groups.length == 0);
279+
if (!excludedGroups.isEmpty() && noGroups) {
280+
return true;
281+
}
278282
return isMemberOf(excludedGroups, groups);
279283
}
280284

src/test/java/test/groupinvocation/GroupSuiteTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.File;
1515
import java.util.ArrayList;
1616
import java.util.Arrays;
17+
import java.util.Collections;
1718
import java.util.List;
1819

1920
import static org.assertj.core.api.Assertions.assertThat;
@@ -123,7 +124,7 @@ private void runWithSuite(String[] withSuiteFiles, boolean groupsWithXml, List<S
123124
test.setExcludedGroups(excludedTestGroups);
124125
}
125126

126-
tng.setXmlSuites(Arrays.asList(suite));
127+
tng.setXmlSuites(Collections.singletonList(suite));
127128

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

137+
@Test(description = "GITHUB-1574")
138+
public void testToCheckNoConfigurationsAreExecuted() {
139+
XmlSuite suite = createXmlSuite("suite");
140+
XmlTest test = createXmlTest(suite, "test", Issue1574TestclassSample.class);
141+
test.addExcludedGroup("sometest");
142+
TestNG testng = create(suite);
143+
testng.run();
144+
assertThat(Issue1574TestclassSample.messages).containsExactly("anothertest","@AfterSuite");
145+
}
146+
136147
private static List<String> g(String... groups) {
137148
return Arrays.asList(groups);
138149
}

0 commit comments

Comments
 (0)