Skip to content

After methods should be skipped when exclusion used - #1575

Closed
krmahadevan wants to merge 1 commit into
testng-team:masterfrom
krmahadevan:krmahadevan-fix-1574
Closed

krmahadevan wants to merge 1 commit into
testng-team:masterfrom
krmahadevan:krmahadevan-fix-1574

Conversation

@krmahadevan

Copy link
Copy Markdown
Member

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.

Fixes #1574 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt

We encourage pull requests that:

  • Add new features to TestNG (or)
  • Fix bugs in TestNG

If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the
TestNG-dev before you spend time working on it.

}

private static boolean isExcluded(Collection<String> excludedGroups, String... groups) {
boolean noGroups = (groups == null || groups.length == 0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

groups cannot be null.

test.addExcludedGroup("sometest");
TestNG testng = create(suite);
testng.run();
assertThat(Issue1574TestclassSample.messages).containsExactly("anothertest","@AfterSuite");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: space missing after ','

import java.util.List;

public class Issue1574TestclassSample {
public static List<String> messages = Lists.newArrayList();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to use InvokedMethodNameListener when possible.

@krmahadevan

Copy link
Copy Markdown
Member Author

@juherr - I have amended the commit and fixed all the comments. Please help take a look

@krmahadevan

Copy link
Copy Markdown
Member Author

ping @juherr - Gentle reminder..

@juherr juherr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is ok but I think it doesn't solve any issue.

@cbeust Could you check #1574 (comment)

}

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: space missing after '=='

@krmahadevan

Copy link
Copy Markdown
Member Author

ping @cbeust - Can you please help comment on this here : #1574 (comment)

I would like to either close this PR if its not a bug or get this merged if its a bug. Please advise.

Closes testng-team#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.
@juherr juherr added the status: needs discussion Awaiting a maintainer decision on scope or design label Nov 12, 2017
@juherr

juherr commented Aug 27, 2026

Copy link
Copy Markdown
Member

Closing this PR since #1574 has now been closed as not planned.

The proposed change would alter the established group-exclusion semantics by excluding ungrouped methods whenever an exclusion is present. Configuration methods that must run regardless of group filtering should use alwaysRun = true.

@juherr juherr closed this Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: needs discussion Awaiting a maintainer decision on scope or design

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Before/After methods are not running when groups "include" in suite

3 participants