MethodOrderer
defines the API for ordering the test methods
in a given test class.
In this context, the term "test method" refers to any method annotated with
@Test
, @RepeatedTest
, @ParameterizedTest
,
@TestFactory
, or @TestTemplate
.
A MethodOrderer
can be configured globally for the entire
test suite via the junit.jupiter.testmethod.order.default configuration
parameter (see the User Guide for details) or locally for a test
class via the @TestMethodOrder
annotation.
JUnit Jupiter provides the following built-in MethodOrderer
implementations.
TestMethodOrder
, MethodOrdererContext
, orderMethods(MethodOrdererContext)
, ClassOrderer
Modifier and Type | Class and Description |
---|---|
public static class | MethodOrderer.
Deprecated
as of JUnit Jupiter 5.7 in favor of MethodOrderer. ;
to be removed in 6.0
MethodOrderer that sorts methods alphanumerically based on their
names using String#compareTo(String) .
|
public static class | MethodOrderer.
|
public static class | MethodOrderer.
|
public static class | MethodOrderer.
|
public static class | MethodOrderer.
|
Modifier and Type | Field and Description |
---|---|
public static final String | DEFAULT_ORDER_PROPERTY_NAME
Property name used to set the default method orderer class name: junit.jupiter.testmethod.order.default Supported Values Supported values include fully qualified class names for types that
implement |
Modifier and Type | Method and Description |
---|---|
public default Optional | Returns: the defaultExecutionMode ; never null but
potentially emptyGet the default |
public void | orderMethods(MethodOrdererContext context)
Order the methods encapsulated in the supplied |
DEFAULT_ORDER_PROPERTY_NAME | back to summary |
---|---|
public static final String DEFAULT_ORDER_PROPERTY_NAME Property name used to set the default method orderer class name: junit.jupiter.testmethod.order.default Supported ValuesSupported values include fully qualified class names for types that
implement If not specified, test methods will be ordered using an algorithm that is deterministic but intentionally non-obvious.
|
getDefaultExecutionMode | back to summary |
---|---|
public default Optional Get the default This method is guaranteed to be invoked after
Defaults to In case the ordering does not conflict with concurrent execution,
implementations should return an empty Can be overridden via an explicit
|
orderMethods | back to summary |
---|---|
public void orderMethods(MethodOrdererContext context) Order the methods encapsulated in the supplied The methods to order or sort are made indirectly available via
For example, a simplified implementation of the public void orderMethods(MethodOrdererContext context) { Collections.shuffle(context.getMethodDescriptors()); }
|
Deprecated
as of JUnit Jupiter 5.7 in favor of MethodOrderer.
;
to be removed in 6.0
MethodOrderer
that sorts methods alphanumerically based on their
names using String#compareTo(String)
.
If two methods have the same name, String
representations of
their formal parameter lists will be used as a fallback for comparing the
methods.
Access | Constructor and Description |
---|---|
public |
Alphanumeric | back to summary |
---|---|
public Alphanumeric() |
MethodOrderer
that sorts methods alphanumerically based on their
display names using String#compareTo(String)
Modifier and Type | Field and Description |
---|---|
private static final Comparator |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public void | orderMethods(MethodOrdererContext context)
Implements org. MethodOrdererContext alphanumerically based on their display
names.
|
comparator | back to summary |
---|---|
private static final Comparator<MethodDescriptor> comparator |
DisplayName | back to summary |
---|---|
public DisplayName() |
orderMethods | back to summary |
---|---|
public void orderMethods(MethodOrdererContext context) Implements org. Sort the methods encapsulated in the supplied
|
MethodOrderer
that sorts methods alphanumerically based on their
names using String#compareTo(String)
.
If two methods have the same name, String
representations of
their formal parameter lists will be used as a fallback for comparing the
methods.
Modifier and Type | Field and Description |
---|---|
private static final Comparator |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
public void | orderMethods(MethodOrdererContext context)
Implements org. MethodOrdererContext alphanumerically based on their names
and formal parameter lists.
|
private static String |
comparator | back to summary |
---|---|
private static final Comparator<MethodDescriptor> comparator |
MethodName | back to summary |
---|---|
public MethodName() |
orderMethods | back to summary |
---|---|
public void orderMethods(MethodOrdererContext context) Implements org. Sort the methods encapsulated in the supplied
|
parameterList | back to summary |
---|---|
private static String parameterList(Method method) |
MethodOrderer
that sorts methods based on the @Order
annotation.
Any methods that are assigned the same order value will be sorted arbitrarily adjacent to each other.
Any methods not annotated with @Order
will be assigned the
default order value which will effectively cause them
to appear at the end of the sorted list, unless certain methods are assigned
an explicit order value greater than the default order value. Any methods
assigned an explicit order value greater than the default order value will
appear after non-annotated methods in the sorted list.
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
private static int | |
public void | orderMethods(MethodOrdererContext context)
Implements org. MethodOrdererContext based on the @Order
annotation.
|
OrderAnnotation | back to summary |
---|---|
public OrderAnnotation() |
getOrder | back to summary |
---|---|
private static int getOrder(MethodDescriptor descriptor) |
orderMethods | back to summary |
---|---|
public void orderMethods(MethodOrdererContext context) Implements org. Sort the methods encapsulated in the supplied
|
MethodOrderer
that orders methods pseudo-randomly.
By default, the random seed used for ordering methods is the
value returned by System#nanoTime()
during static initialization
of this class. In order to support repeatable builds, the value of the
default random seed is logged at CONFIG
level. In addition, a
custom seed (potentially the default seed from the previous test plan
execution) may be specified via the junit.jupiter.execution.order.random.seed
configuration parameter which can be supplied via the Launcher
API, build tools (e.g., Gradle and Maven), a JVM system property, or the JUnit
Platform configuration file (i.e., a file named junit-platform.properties
in the root of the class path). Consult the User Guide for further information.
Modifier and Type | Field and Description |
---|---|
private static final long | DEFAULT_SEED
Default seed, which is generated during initialization of this class
via |
private static final Logger | |
public static final String | RANDOM_SEED_PROPERTY_NAME
Property name used to set the random seed used by this
The same property is used by |
Access | Constructor and Description |
---|---|
public |
Modifier and Type | Method and Description |
---|---|
private Optional | |
public void | orderMethods(MethodOrdererContext context)
Implements org. MethodOrdererContext pseudo-randomly.
|
DEFAULT_SEED | back to summary |
---|---|
private static final long DEFAULT_SEED Default seed, which is generated during initialization of this class
via |
logger | back to summary |
---|---|
private static final Logger logger |
RANDOM_SEED_PROPERTY_NAME | back to summary |
---|---|
public static final String RANDOM_SEED_PROPERTY_NAME Property name used to set the random seed used by this
The same property is used by Supported ValuesSupported values include any string that can be converted to a
If not specified or if the specified value cannot be converted to
a
|
Random | back to summary |
---|---|
public Random() |
getCustomSeed | back to summary |
---|---|
private Optional |
orderMethods | back to summary |
---|---|
public void orderMethods(MethodOrdererContext context) Implements org. Order the methods encapsulated in the supplied
|