Skip to content

Inherit @TestClassOrder and @TestMethodOrder within @Nested hierarchies #4731

@sbrannen

Description

@sbrannen

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions