Annotation Interface ExtendWith
@ExtendWith is 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 @AfterEach lifecycle methods.
@ExtendWith fields may be either static or non-static.
Inheritance
@ExtendWith fields are inherited from superclasses. Furthermore,
@ExtendWith fields from superclasses will be registered before
@ExtendWith fields in subclasses unless @Order is used to
alter that behavior (see below).
Registration Order
When @ExtendWith is 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
@ExtendWith annotations are discovered. For example, if a test class
is annotated with @ExtendWith(A.class) and then with
@ExtendWith(B.class), extension A will be registered before
extension B.
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
@ExtendWith fields with @Order.
Any @ExtendWith field not annotated with @Order will be
ordered using the default order
value. Note that @RegisterExtension fields can also be ordered with
@Order, relative to @ExtendWith fields and other
@RegisterExtension fields.
Supported Extension APIs
ExecutionConditionInvocationInterceptorBeforeAllCallbackAfterAllCallbackBeforeEachCallbackAfterEachCallbackBeforeTestExecutionCallbackAfterTestExecutionCallbackTestInstanceFactoryTestInstancePostProcessorTestInstancePreConstructCallbackTestInstancePreDestroyCallbackParameterResolverLifecycleMethodExecutionExceptionHandlerTestExecutionExceptionHandlerTestTemplateInvocationContextProviderTestWatcher
- Since:
- 5.0
- See Also:
-
Required Element Summary
Required Elements
-
Element Details
-
value
An array of one or moreExtensionclasses to register.
-