Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After methods should be skipped when exclusion used #1575

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-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
Original file line number Diff line number Diff line change
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
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,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
Original file line number Diff line number Diff line change
@@ -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() {
}
}