Closed magicwerk closed 9 months ago
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!
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