Top Description Methods
org.junit.jupiter.api

public @Interface TestMethodOrder

extends Annotation
Annotations
@Target:TYPE
@Retention:RUNTIME
@Documented
@Inherited
@API
status:STABLE
since:5.7
Static Imports
org.apiguardian.api.API.Status.STABLE

@TestMethodOrder is a type-level annotation that is used to configure a MethodOrderer for the test methods of the annotated test class or test interface.

In this context, the term "test method" refers to any method annotated with @Test, @RepeatedTest, @ParameterizedTest, @TestFactory, or @TestTemplate.

If @TestMethodOrder is not explicitly declared on a test class, inherited from a parent class, or declared on a test interface implemented by a test class, test methods will be ordered using a default algorithm that is deterministic but intentionally nonobvious.

As an alternative to @TestMethodOrder, a global MethodOrderer can be configured for the entire test suite via the junit.jupiter.testmethod.order.default configuration parameter. See the User Guide for details. Note, however, that a @TestClassOrder declaration always overrides a global ClassOrderer.

Example Usage

The following demonstrates how to guarantee that test methods are executed in the order specified via the @Order annotation.

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class OrderedTests {

    @Test
    @Order(1)
    void nullValues() {}

    @Test
    @Order(2)
    void emptyValues() {}

    @Test
    @Order(3)
    void validValues() {}
}
Since
5.4
See Also
MethodOrderer, TestClassOrder

Method Summary

Modifier and TypeMethod and Description
public Class<? extends MethodOrderer>
value()

The MethodOrderer to use.

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public Class<? extends MethodOrderer> value()

The MethodOrderer to use.

See Also
MethodOrderer, MethodOrderer.MethodName, MethodOrderer.DisplayName, MethodOrderer.OrderAnnotation, MethodOrderer.Random