-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Overview
While upgrading the Spring Framework test suite to use JUnit 5.13, I noticed a discovery issue warning that @Order annotations were declared on test methods within a @Nested test class without proper configuration of the OrderAnnotation MethodOrderer.
However, the enclosing class was annotated with @TestMethodOrder(OrderAnnotation.class).
Thus, it became apparent that @TestMethodOrder is currently not inherited for @Nested test classes.
For Spring, I simply redeclared @TestMethodOrder on the @Nested test class, and the warning went away.
Proposal
It would be very useful if @Nested test classes inherited a @TestMethodOrder configured on an enclosing class.
However, there would then be no way to "turn off" the inherited MethodOrderer. To address that, I propose that we also introduce a new, no-op Default MethodOrderer which effectively signals that the "default" MethodOrderer should be used.
@TestClassOrder should also be inherited by default within @Nested test class hierarchies, and a Default implementation of ClassOrderer will also be necessary.
MethodOrderingVisitor.orderContainedMethods() and ClassOrderingVisitor.createClassLevelOrderer() will need to be updated accordingly to take into account Default orderers.
Deliverables
- Inherit
@TestMethodOrderto nested test classes - Inherit
@TestClassOrderto nested test classes - Introduce
MethodOrderer.Defaultthat can be used to opt-out and use the default orderer specified via thejunit.jupiter.testmethod.order.defaultconfiguration parameter (or none if the configuration parameter is not set) - Introduce
ClassOrderer.Defaultthat can be used to opt-out and use the default orderer specified via thejunit.jupiter.testclass.order.defaultconfiguration parameter (or none if the configuration parameter is not set)