Annotation Type ExtendWith
-
@Target({TYPE,METHOD,FIELD,PARAMETER}) @Retention(RUNTIME) @Documented @Inherited @Repeatable(Extensions.class) @API(status=STABLE, since="5.0") public @interface ExtendWith@ExtendWithis a repeatable annotation that is used to register extensions for the annotated test class, test interface, test method, parameter, or field.Annotated parameters are supported in test class constructors, in test methods, and in
@BeforeAll,@AfterAll,@BeforeEach, and@AfterEachlifecycle methods.@ExtendWithfields may be eitherstaticor non-static.Inheritance
@ExtendWithfields are inherited from superclasses. Furthermore,@ExtendWithfields from superclasses will be registered before@ExtendWithfields in subclasses unless@Orderis used to alter that behavior (see below).Registration Order
When
@ExtendWithis present on a test class, test interface, or test method or on a parameter in a test method or lifecycle method, the corresponding extensions will be registered in the order in which the@ExtendWithannotations are discovered. For example, if a test class is annotated with@ExtendWith(A.class)and then with@ExtendWith(B.class), extensionAwill be registered before extensionB.By default, if multiple extensions are registered on fields via
@ExtendWith, they will be ordered using an algorithm that is deterministic but intentionally nonobvious. This ensures that subsequent runs of a test suite execute extensions in the same order, thereby allowing for repeatable builds. However, there are times when extensions need to be registered in an explicit order. To achieve that, you can annotate@ExtendWithfields with@Order. Any@ExtendWithfield not annotated with@Orderwill be ordered using thedefaultorder value. Note that@RegisterExtensionfields can also be ordered with@Order, relative to@ExtendWithfields and other@RegisterExtensionfields.Supported Extension APIs
ExecutionConditionInvocationInterceptorBeforeAllCallbackAfterAllCallbackBeforeEachCallbackAfterEachCallbackBeforeTestExecutionCallbackAfterTestExecutionCallbackTestInstanceFactoryTestInstancePostProcessorTestInstancePreConstructCallbackTestInstancePreDestroyCallbackParameterResolverLifecycleMethodExecutionExceptionHandlerTestExecutionExceptionHandlerTestTemplateInvocationContextProviderTestWatcher
- Since:
- 5.0
- See Also:
RegisterExtension,Extension