Interface TestInstancePreConstructCallback
- All Superinterfaces:
Extension
,TestInstantiationAwareExtension
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
TestInstancePreConstructCallback
defines the API for Extensions
that wish to be invoked prior to creation of test instances.
This extension is a symmetric counterpart to TestInstancePreDestroyCallback
.
The use cases for this extension may include preparing context-sensitive arguments
that are injected into the instance's constructor.
Extensions that implement TestInstancePreConstructCallback
must be
registered at the class level if the test class is configured with
@TestInstance(Lifecycle.PER_CLASS)
semantics. If the test
class is configured with
@TestInstance(Lifecycle.PER_METHOD)
semantics,
TestInstancePreConstructCallback
extensions may be registered at the
class level or at the method level. In the latter case, the extension will
only be applied to the test method for which it is registered.
Constructor Requirements
Consult the documentation in Extension
for details on constructor
requirements.
- Since:
- 5.9
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
TestInstantiationAwareExtension.ExtensionContextScope
-
Method Summary
Modifier and TypeMethodDescriptionvoid
preConstructTestInstance
(TestInstanceFactoryContext factoryContext, ExtensionContext context) Callback invoked prior to test instances being constructed.Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Method Details
-
preConstructTestInstance
void preConstructTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext context) throws Exception Callback invoked prior to test instances being constructed.By default, the supplied
ExtensionContext
represents the test class that's about to be constructed. Extensions may overrideTestInstantiationAwareExtension.getTestInstantiationExtensionContextScope(org.junit.jupiter.api.extension.ExtensionContext)
to returnTEST_METHOD
in order to change the scope of theExtensionContext
to the test method, unless thePER_CLASS
lifecycle is used. Changing the scope makes test-specific data available to the implementation of this method and allows keeping state on the test level by using the providedStore
instance.- Parameters:
factoryContext
- the context for the test instance about to be instantiated; nevernull
context
- the current extension context; nevernull
- Throws:
Exception
-