@API(status=STABLE,
since="5.10")
public interface ClassOrderer
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.
JUnit Jupiter provides the following built-in ClassOrderer
implementations.
TestClassOrder,
ClassOrdererContext,
orderClasses(ClassOrdererContext),
MethodOrderer| Modifier and Type | Interface and Description |
|---|---|
static class |
ClassOrderer.ClassName
ClassOrderer that sorts classes alphanumerically based on their
fully qualified names using String.compareTo(String). |
static class |
ClassOrderer.DisplayName
ClassOrderer that sorts classes alphanumerically based on their
display names using String.compareTo(String) |
static class |
ClassOrderer.OrderAnnotation
ClassOrderer that sorts classes based on the @Order
annotation. |
static class |
ClassOrderer.Random
ClassOrderer that orders classes pseudo-randomly. |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
DEFAULT_ORDER_PROPERTY_NAME
Property name used to set the default class orderer class name: "junit.jupiter.testclass.order.default"
|
| Modifier and Type | Method and Description |
|---|---|
void |
orderClasses(ClassOrdererContext context)
Order the classes encapsulated in the supplied
ClassOrdererContext. |
@API(status=STABLE,
since="5.9")
static final java.lang.String DEFAULT_ORDER_PROPERTY_NAME
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.
void orderClasses(ClassOrdererContext context)
ClassOrdererContext.
The classes to order or sort are made indirectly available via
ClassOrdererContext.getClassDescriptors(). Since this method
has a void return type, the list of class descriptors must be
modified directly.
For example, a simplified implementation of the ClassOrderer.Random
ClassOrderer might look like the following.
public void orderClasses(ClassOrdererContext context) {
Collections.shuffle(context.getClassDescriptors());
}
context - the ClassOrdererContext containing the
class descriptors to order; never null