Align method filtering behavior between JUnit and TestNG#3227
Closed
pdolif wants to merge 1 commit intoapache:masterfrom
Closed
Align method filtering behavior between JUnit and TestNG#3227pdolif wants to merge 1 commit intoapache:masterfrom
pdolif wants to merge 1 commit intoapache:masterfrom
Conversation
Member
|
Could you please check with this PR #3179 as the big refactoring might land very soon now |
Author
|
@olamy The integration test added in this PR succeeds with PR #3179. |
Contributor
Member
|
this is typically the kind of duplicated code which will not be needed anymore with #3179 |
Contributor
|
@Tibor17 At the moment, it works without breaking anything. To me, FakeClass doesn’t sound any stranger than FakeTestMethod. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3225
This PR aligns the method filtering behavior between JUnit and TestNG by adjusting the TestNG MethodSelector.
Problem
Given the following test classes:
When using an includesFile containing SubClass only,
testInSubClassandtestInSuperClassare executed (as expected).If the includesFile does not only contain class filters but also method filters, the behavior is different (with TestNG only), and
testInSuperClassis not executed anymore.Example includesFile:
With this, only
testInSubClassandOtherClass#testIncludedare executed.Root Cause
TestNG uses the MethodSelector for filtering the tests. For
testInSuperClass()the MethodSelector is invoked with an ITestNGMethod instance like this:getRealClass()returns SuperClassgetTestClass().getRealClass()returns SubClassThe current MethodSelector implementation uses
getRealClass()and then checks whether to runSuperClass#testInSuperClass. If we have SubClass in the includesFile, the test will not be executed, even though SubClass inherits it. This is different when using JUnit instead of TestNG.Fix
This PR changes the MethodSelector implementation to use
getTestClass().getRealClass()to check whether to run a test. The behavior changes as follows:testInSuperClassgets executed too.SubClass#testInSuperClassin the includesFile, prior to this PR no test was executed. NowSubClass#testInSuperClassgets executed.SuperClass#testInSuperClassin the excludesFile, prior to this PR onlySubClass#testInSubClassgot executed. Now the inherited testSubClass#testInSuperClassgets executed too.The PR includes tests that are executed with TestNG and JUnit to ensure the behavior aligns.
Following this checklist to help us incorporate your
contribution quickly and easily:
mvn clean installto make sure basic checks pass. A more thorough check willbe performed on your pull request automatically.
mvn -Prun-its clean install).If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.
To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.
I hereby declare this contribution to be licenced under the Apache License Version 2.0, January 2004
In any other case, please file an Apache Individual Contributor License Agreement.