Interface MethodOrderer

All Known Implementing Classes:
MethodOrderer.Alphanumeric, MethodOrderer.DisplayName, MethodOrderer.MethodName, MethodOrderer.OrderAnnotation, MethodOrderer.Random

@API(status=STABLE, since="5.7") public interface MethodOrderer
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.

Built-in Implementations

JUnit Jupiter provides the following built-in MethodOrderer implementations.

See Also:
  • Field Details


      @API(status=STABLE, since="5.9") 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 MethodOrderer.

      If not specified, test methods will be ordered using an algorithm that is deterministic but intentionally non-obvious.

      See Also:
  • Method Details

    • orderMethods

      void orderMethods(MethodOrdererContext context)
      Order the methods encapsulated in the supplied MethodOrdererContext.

      The methods to order or sort are made indirectly available via MethodOrdererContext.getMethodDescriptors(). Since this method has a void return type, the list of method descriptors must be modified directly.

      For example, a simplified implementation of the MethodOrderer.Random MethodOrderer might look like the following.

       public void orderMethods(MethodOrdererContext context) {
      context - the MethodOrdererContext containing the method descriptors to order; never null
      See Also:
    • getDefaultExecutionMode

      default Optional<ExecutionMode> getDefaultExecutionMode()
      Get the default ExecutionMode for the test class configured with this MethodOrderer.

      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 in orderMethods().

      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 Optional to signal that the engine should decide which execution mode to use.

      Can be overridden via an explicit @Execution declaration on the test class or in concrete implementations of the MethodOrderer API.

      the default ExecutionMode; never null but potentially empty
      See Also: