Annotation Type TestInstance
-
@Target(TYPE) @Retention(RUNTIME) @Inherited @Documented @API(status=STABLE, since="5.0") public @interface TestInstance@TestInstanceis a type-level annotation that is used to configure the lifecycle of test instances for the annotated test class or test interface.If
@TestInstanceis not explicitly declared on a test class or on a test interface implemented by a test class, the lifecycle mode will implicitly default toPER_METHOD. Note, however, that an explicit lifecycle mode is inherited within a test class hierarchy. In addition, the default lifecycle mode may be overridden via thejunit.jupiter.testinstance.lifecycle.defaultconfiguration parameter which can be supplied via theLauncherAPI, build tools (e.g., Gradle and Maven), a JVM system property, or the JUnit Platform configuration file (i.e., a file namedjunit-platform.propertiesin the root of the class path). Consult the User Guide for further information.Use Cases
Setting the test instance lifecycle mode to
PER_CLASSenables the following features.- Shared test instance state between test methods in a given test class
as well as between non-static
@BeforeAlland@AfterAllmethods in the test class. - Declaration of
@BeforeAlland@AfterAllmethods in@Nestedtest classes. - Declaration of
@BeforeAlland@AfterAllon interfacedefaultmethods. - Simplified declaration of
@BeforeAlland@AfterAllmethods in test classes implemented with the Kotlin programming language.
@TestInstancemay also be used as a meta-annotation in order to create a custom composed annotation that inherits the semantics of@TestInstance.- Since:
- 5.0
- See Also:
@Nested
- Shared test instance state between test methods in a given test class
as well as between non-static
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description TestInstance.LifecyclevalueThe test instance lifecycle mode to use.
-
-
-
Element Detail
-
value
TestInstance.Lifecycle value
The test instance lifecycle mode to use.
-
-