Annotation Type Test
-
@Target({ANNOTATION_TYPE,METHOD}) @Retention(RUNTIME) @Documented @API(status=STABLE, since="5.0") @Testable public @interface Test@Testis used to signal that the annotated method is a test method.@Testmethods must not beprivateorstaticand must not return a value.@Testmethods may optionally declare parameters to be resolved byParameterResolvers.@Testmay also be used as a meta-annotation in order to create a custom composed annotation that inherits the semantics of@Test.Inheritance
@Testmethods are inherited from superclasses as long as they are not overridden according to the visibility rules of the Java language. Similarly,@Testmethods declared as interface default methods are inherited as long as they are not overridden.Test Execution Order
By default, test methods will be ordered using an algorithm that is deterministic but intentionally nonobvious. This ensures that subsequent runs of a test suite execute test methods in the same order, thereby allowing for repeatable builds. In this context, a test method is any instance method that is directly annotated or meta-annotated with
@Test,@RepeatedTest,@ParameterizedTest,@TestFactory, or@TestTemplate.Although true unit tests typically should not rely on the order in which they are executed, there are times when it is necessary to enforce a specific test method execution order?—?for example, when writing integration tests or functional tests where the sequence of the tests is important, especially in conjunction with
@TestInstance(Lifecycle.PER_CLASS).To control the order in which test methods are executed, annotate your test class or test interface with
@TestMethodOrderand specify the desiredMethodOrdererimplementation.- Since:
- 5.0
- See Also:
RepeatedTest,org.junit.jupiter.params.ParameterizedTest,TestTemplate,TestFactory,TestInfo,DisplayName,Tag,BeforeAll,AfterAll,BeforeEach,AfterEach