Interface ClassOrderer
- All Known Implementing Classes:
ClassOrderer.ClassName, ClassOrderer.Default, ClassOrderer.DisplayName, ClassOrderer.OrderAnnotation, ClassOrderer.Random
ClassOrderer defines the API for ordering top-level test classes and
@Nested test classes.
In this context, the term "test class" refers to any class containing methods
annotated with @Test, @RepeatedTest, @ParameterizedTest,
@TestFactory, or @TestTemplate.
Top-level test classes will be ordered relative to each other; whereas,
@Nested test classes will be ordered relative to other @Nested
test classes sharing the same enclosing
class.
A ClassOrderer can be configured globally for the entire
test suite via the "junit.jupiter.testclass.order.default" configuration
parameter (see the User Guide for details) or locally for
@Nested test classes via the @TestClassOrder
annotation.
Built-in Implementations
JUnit Jupiter provides the following built-in ClassOrderer
implementations.
- Since:
- 5.8
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classClassOrdererthat sorts classes alphanumerically based on their fully qualified names usingString.compareTo(String).static final classClassOrdererthat allows to explicitly specify that the default ordering should be applied.static classClassOrdererthat sorts classes alphanumerically based on their display names usingString.compareTo(String)static classClassOrdererthat sorts classes based on the@Orderannotation.static classClassOrdererthat orders classes pseudo-randomly. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty name used to set the default class orderer class name: "junit.jupiter.testclass.order.default" -
Method Summary
Modifier and TypeMethodDescriptionvoidorderClasses(ClassOrdererContext context) Order the classes encapsulated in the suppliedClassOrdererContext.
-
Field Details
-
DEFAULT_ORDER_PROPERTY_NAME
Property name used to set the default class orderer class name: "junit.jupiter.testclass.order.default"Supported Values
Supported values include fully qualified class names for types that implement
ClassOrderer.If not specified, test classes are not ordered unless test classes are annotated with
@TestClassOrder.- Since:
- 5.8
- See Also:
-
-
Method Details
-
orderClasses
Order the classes encapsulated in the suppliedClassOrdererContext.The classes to order or sort are made indirectly available via
ClassOrdererContext.getClassDescriptors(). Since this method has avoidreturn type, the list of class descriptors must be modified directly.For example, a simplified implementation of the
ClassOrderer.RandomClassOrderermight look like the following.public void orderClasses(ClassOrdererContext context) { Collections.shuffle(context.getClassDescriptors()); }- Parameters:
context- theClassOrdererContextcontaining the class descriptors to order; nevernull
-