Interface MethodOrderer
-
- All Known Implementing Classes:
MethodOrderer.Alphanumeric,MethodOrderer.DisplayName,MethodOrderer.MethodName,MethodOrderer.OrderAnnotation,MethodOrderer.Random
@API(status=STABLE, since="5.7") public interface MethodOrdererMethodOrdererdefines 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
MethodOrderercan 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@TestMethodOrderannotation.Built-in Implementations
JUnit Jupiter provides the following built-in
MethodOrdererimplementations.- Since:
- 5.4
- See Also:
TestMethodOrder,MethodOrdererContext,orderMethods(MethodOrdererContext),ClassOrderer
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classMethodOrderer.AlphanumericDeprecated.as of JUnit Jupiter 5.7 in favor ofMethodOrderer.MethodName; to be removed in 6.0static classMethodOrderer.DisplayNameMethodOrdererthat sorts methods alphanumerically based on their display names usingString.compareTo(String)static classMethodOrderer.MethodNameMethodOrdererthat sorts methods alphanumerically based on their names usingString.compareTo(String).static classMethodOrderer.OrderAnnotationMethodOrdererthat sorts methods based on the@Orderannotation.static classMethodOrderer.RandomMethodOrdererthat orders methods pseudo-randomly.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_ORDER_PROPERTY_NAMEProperty name used to set the default method orderer class name: "junit.jupiter.testmethod.order.default"
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.util.Optional<ExecutionMode>getDefaultExecutionMode()Get the defaultExecutionModefor the test class configured with thisMethodOrderer.voidorderMethods(MethodOrdererContext context)Order the methods encapsulated in the suppliedMethodOrdererContext.
-
-
-
Field Detail
-
DEFAULT_ORDER_PROPERTY_NAME
@API(status=STABLE, since="5.9") static final java.lang.String DEFAULT_ORDER_PROPERTY_NAMEProperty 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
MethodOrderer.If not specified, test methods will be ordered using an algorithm that is deterministic but intentionally non-obvious.
- Since:
- 5.7
- See Also:
- Constant Field Values
-
-
Method Detail
-
orderMethods
void orderMethods(MethodOrdererContext context)
Order the methods encapsulated in the suppliedMethodOrdererContext.The methods to order or sort are made indirectly available via
MethodOrdererContext.getMethodDescriptors(). Since this method has avoidreturn type, the list of method descriptors must be modified directly.For example, a simplified implementation of the
MethodOrderer.RandomMethodOrderermight look like the following.public void orderMethods(MethodOrdererContext context) { Collections.shuffle(context.getMethodDescriptors()); }- Parameters:
context- theMethodOrdererContextcontaining the method descriptors to order; nevernull- See Also:
getDefaultExecutionMode()
-
getDefaultExecutionMode
default java.util.Optional<ExecutionMode> getDefaultExecutionMode()
Get the defaultExecutionModefor the test class configured with thisMethodOrderer.This method is guaranteed to be invoked after
orderMethods(MethodOrdererContext)which allows implementations of this method to determine the appropriate return value programmatically, potentially based on actions that were taken inorderMethods().Defaults to
SAME_THREAD, since ordered methods are typically sorted in a fashion that would conflict with concurrent execution.In case the ordering does not conflict with concurrent execution, implementations should return an empty
Optionalto signal that the engine should decide which execution mode to use.Can be overridden via an explicit
@Executiondeclaration on the test class or in concrete implementations of theMethodOrdererAPI.- Returns:
- the default
ExecutionMode; nevernullbut potentially empty - See Also:
orderMethods(MethodOrdererContext)
-
-