-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
JUnit 5 computes overrides relationships incorrectly #2390
Comments
Tentatively slated for 5.8 M1 solely for the purpose of team discussion. |
This appears to be a duplicate of another issue raised about package private test methods with the same signature but in different packages, though I can't seem to find that issue at the moment. |
Closing with rationale explained in #960 (comment). |
I disagree with closing this as a duplicate. The referred issue does not deal with packages - it only concerns finding annotations. Let's imagine two packages and a class in each:
We can then write a table of expected behavior based on the modifiers:
The combinations with (*) instead produce:
which is inconsistent with documentation:
First - private methods are actually executed too! Either my understanding of Java method overriding, or those who sentences in JavaDoc is wrong, or this is really a bug - and it is up to JUnit 5 project to decide whether to fix it by changing the behavior to be consistent with documentation (breaking change), or update the documentation to cover all cases or mention that when methods have the same name the execution is not reliable (similar thing is there already for execution order of multiple methods within one class). |
@juriad, this issue was closed 1.5 years ago. Please open a new issue to discuss your points. With regard to private methods, those should not be executed. So that sounds like a bug. With regard to the use of the term "overridden", the documentation should likely be updated to say "overridden or shadowed". |
This comment was marked as outdated.
This comment was marked as outdated.
@tjwilson90 and @juriad, please note that this issue has been effectively superseded by the following, which will be included in 5.11 M1 for early testing. |
junit-platform-commons:1.6.0
This outputs
but should output
The reason it does not output
foo
is becauseReflectionUtils.isMethodShadowedBy
is used to compute overrides while scanning for all methods in a class hierarchy. That considers only the signature of the method which is not sufficient according to the language specification, https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.8.1The reason why I care about this is because I want to declare a
@BeforeEach
method in a super class and always have it execute regardless of what subclasses are doing.The text was updated successfully, but these errors were encountered: