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 24, 2017
1 parent f39036f commit 324bb80
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
1 change: 1 addition & 0 deletions 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)
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/testng/internal/XmlMethodSelector.java
Expand Up @@ -275,6 +275,9 @@ private static boolean isIncluded(Collection<String> includedGroups, boolean noG
}

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

Expand Down
15 changes: 14 additions & 1 deletion src/test/java/test/groupinvocation/GroupSuiteTest.java
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,18 @@ 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);
InvokedMethodNameListener listener = new InvokedMethodNameListener();
testng.addListener((ITestNGListener) listener);
testng.run();
assertThat(listener.getInvokedMethodNames()).containsExactly("anothertest", "tearDownSuite");
}

private static List<String> g(String... groups) {
return Arrays.asList(groups);
}
Expand Down
43 changes: 43 additions & 0 deletions 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() {
}
}

0 comments on commit 324bb80

Please sign in to comment.