@Target(value=TYPE) @Retention(value=RUNTIME) @Inherited @Documented @API(status=STABLE, since="5.0") public @interface TestInstance
@TestInstance
is a type-level annotation that is used to configure
the lifecycle of test instances for the annotated
test class or test interface.
If @TestInstance
is not declared on a test class or implemented
test interface, the lifecycle mode will implicitly default to
PER_METHOD
. Note, however, that an explicit
lifecycle mode is inherited within a test class hierarchy. In
addition, the default lifecycle mode may be set via the
junit.jupiter.testinstance.lifecycle.default
configuration
parameter which can be supplied via the Launcher
API or via a
JVM system property. Consult the User Guide for further information.
Setting the test instance lifecycle mode to PER_CLASS
enables the following features.
@BeforeAll
and
@AfterAll
methods in the test class.@BeforeAll
and @AfterAll
methods in @Nested
test classes.@BeforeAll
and @AfterAll
on interface default
methods.@BeforeAll
and
@AfterAll
methods in test classes implemented with the Kotlin
programming language.@TestInstance
may also be used as a meta-annotation in order to
create a custom composed annotation that inherits the semantics
of @TestInstance
.
Modifier and Type | Required Element and Description |
---|---|
TestInstance.Lifecycle |
value
The test instance lifecycle mode to use.
|
public abstract TestInstance.Lifecycle value