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

Inherited lifecycle annotations are not migrated properly #443

Closed
magicwerk opened this issue Dec 18, 2023 · 1 comment · Fixed by #444
Closed

Inherited lifecycle annotations are not migrated properly #443

magicwerk opened this issue Dec 18, 2023 · 1 comment · Fixed by #444
Assignees
Labels
recipe Recipe request

Comments

@magicwerk
Copy link
Contributor

magicwerk commented Dec 18, 2023

What problem are you trying to solve?

JUnit 5 changed the way inherited lifecycle annotations are handled.
Lifecycle annotations are inherited from superclasses as long as they are not overridden,
i.e. if you override a lifecycle method, the annotation must be repeated.
This is different from JUnit 4 where the annotation had not to be repeated in the overriding class.

Reference:
https://junit.org/junit5/docs/5.0.1/api/org/junit/jupiter/api/BeforeEach.html
@beforeeach methods are inherited from superclasses as long as they are not overridden

The current implementation makes JUnit 4 such tests fail after running the JUnit4to5Migration recipe as the lifecycle methods are not executed anymore.

I propose to add a recipe AddMissingTestBeforeAfterAnnotations which will add
the missing annotations
@test, @beforeeach, @AfterEach
if they are found on a superclass and not present on the class analyzed.

Are you interested in contributing this recipe to OpenRewrite?

Yes, I would try to contribute a PR

@timtebeek timtebeek added the recipe Recipe request label Dec 18, 2023
@timtebeek
Copy link
Contributor

Perfect suggestion indeed @magicwerk . From #442 I think you've spotted the TypeUtils.isOverride that was used there, that should help inform where any such annotations might be missing. Feel free to immediately tie your recipe into the JUnit4to5Migration, as I expect this to be a required step there. And thanks a lot for the offer to help; look forward to your PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
recipe Recipe request
Projects
Archived in project
2 participants