-
-
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
Private lifecycle methods should cause an exception #2914
Comments
Quoting my previous feedback in #2390 (comment): 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" [although the term "shadowed" may be misleading with regard to the definition of the term in the JLS]. |
Team decision: Throw an exception when encountering them similar to what is done when they're static.
Team decision: Clarify documentation. |
Private lifecycle methods no longer allowed junit-team/junit5#2914
Private lifecycle methods no longer allowed junit-team/junit5#2914
In the new version of JUnit it is enforced that lifecycle methods are not private. junit-team/junit5#2914 Change-Id: Iee080d2641c762cf936167c930884d8b4e8c7f07
FYI, we did a quick search of Amazon's codebase and found 5,787 results for using |
@rschmitt Thanks for letting us know! However, the new behavior aligns with what was already documented and the required changes are minimal. There are tools to help with large-scale refactorings such as https://github.com/openrewrite/rewrite. |
Nevertheless, it is a breaking change; compatibility is determined by actual behavior, not by documented behavior. Is this change strategically important for you, e.g. will it dramatically simplify JUnit's internals or make it easier to ship improvements in the future? Or was it done solely to match the documentation? I'll note that you could have changed the documentation as easily as changing the code, and documentation changes never break anyone. Personally, I always declare test and lifecycle methods In addition, the JDK maintainers are increasingly shutting off access to any capabilities that "affect platform and application integrity" unless the application opts in to them by passing a JVM flag. Will
Not for me. In our build system, we have modeled JUnit 5 as a single major version, If you'd like, we can work together in the future to catch these types of breaking changes before they are released, or to empirically assess the impact of slightly breaking changes that it may be possible to get away with. We have the ability to dryrun build pre-release versions of JUnit, which will immediately build and test over 15,000 Java packages against whichever JUnit version you like, and we can probably have the results for you in a day or two. Would this be valuable to you? |
@rschmitt Thanks for your detailed response. We'll discuss it internally and will get back to you. |
Fortunately we had to change only ~70 test classes in our code base that allows us to update to JUnit 5.9. |
Team decision: Revert the validation but document |
The JavaDoc contains the following sentences:
Private methods are executed, even though they should not be (?). The JavaDoc prohibits private methods but does not explain what will happen.
Java defines overriding methods as: https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.8.1, the JavaDoc uses the term "overridden" with a different meaning than Java. JLS even says:
In the previous issue #2390, it was suggested to also include mention of shadowing - which I think is also wrong. JLS already defines shadowing - https://docs.oracle.com/javase/specs/jls/se8/html/jls-6.html#jls-6.4.1.
Both instances should be either fixed to be compliant with the documentation, or the documentation should be updated.
Other annotations (
@BeforeAll
,@AfterAll
, and@AfterEach
) are expected to be affected too.Steps to reproduce
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:
Context
The text was updated successfully, but these errors were encountered: