/*
 * Copyright 2015-2020 the original author or authors.
 *
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v2.0 which
 * accompanies this distribution and is available at
 *
 * https://www.eclipse.org/legal/epl-v20.html
 */

package org.junit.jupiter.api;

import static org.apiguardian.api.API.Status.STABLE;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.apiguardian.api.API;

@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.

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() {} } 
See Also:
Since:5.4
/** * {@code @TestMethodOrder} is a type-level annotation that is used to configure * a {@link #value MethodOrderer} for the <em>test methods</em> of the annotated * test class or test interface. * * <p>In this context, the term "test method" refers to any method annotated with * {@code @Test}, {@code @RepeatedTest}, {@code @ParameterizedTest}, * {@code @TestFactory}, or {@code @TestTemplate}. * * <p>If {@code @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. * * <h4>Example Usage</h4> * * <p>The following demonstrates how to guarantee that test methods are executed * in the order specified via the {@link Order @Order} annotation. * * <pre class="code"> * {@literal @}TestMethodOrder(MethodOrderer.OrderAnnotation.class) * class OrderedTests { * * {@literal @}Test * {@literal @}Order(1) * void nullValues() {} * * {@literal @}Test * {@literal @}Order(2) * void emptyValues() {} * * {@literal @}Test * {@literal @}Order(3) * void validValues() {} * } * </pre> * * @since 5.4 * @see MethodOrderer */
@Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @API(status = STABLE, since = "5.7") public @interface TestMethodOrder {
The MethodOrderer to use.
See Also:
/** * The {@link MethodOrderer} to use. * * @see MethodOrderer * @see MethodOrderer.MethodName * @see MethodOrderer.DisplayName * @see MethodOrderer.OrderAnnotation * @see MethodOrderer.Random */
Class<? extends MethodOrderer> value(); }