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.
@FunctionalInterface @API(status=STABLE, since="5.11") public interface TestInstancePreConstructCallback extends TestInstantiationAwareExtensionTestInstancePreConstructCallbackdefines the API forExtensionsthat 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
TestInstancePreConstructCallbackmust 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,TestInstancePreConstructCallbackextensions 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
Extensionfor details on constructor requirements.ExtensionContextScopeAs of JUnit Jupiter 5.12, this API participates in the
TestInstantiationAwareExtensioncontract. Implementations of this API may therefore choose to overridegetTestInstantiationExtensionContextScope(ExtensionContext)to require a test-method scopedExtensionContext. SeepreConstructTestInstance(TestInstanceFactoryContext, ExtensionContext)for further details.- Since:
- 5.9
- See Also:
TestInstancePreDestroyCallback,TestInstanceFactory,ParameterResolver
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
TestInstantiationAwareExtension.ExtensionContextScope
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidpreConstructTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext context)Callback invoked prior to test instances being constructed.-
Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
-
-
-
Method Detail
-
preConstructTestInstance
void preConstructTestInstance(TestInstanceFactoryContext factoryContext, ExtensionContext context) throws java.lang.Exception
Callback invoked prior to test instances being constructed.By default, the supplied
ExtensionContextrepresents the test class that's about to be constructed. Extensions may overrideTestInstantiationAwareExtension.getTestInstantiationExtensionContextScope(org.junit.jupiter.api.extension.ExtensionContext)to returnTEST_METHODin order to change the scope of theExtensionContextto the test method, unless thePER_CLASSlifecycle 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 providedStoreinstance.- Parameters:
factoryContext- the context for the test instance about to be instantiated; nevernullcontext- the current extension context; nevernull- Throws:
java.lang.Exception
-
-