Interface TestInstancePostProcessor
-
- 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.0") public interface TestInstancePostProcessor extends TestInstantiationAwareExtensionTestInstancePostProcessordefines the API forExtensionsthat wish to post-process test instances.Common use cases include injecting dependencies into the test instance, invoking custom initialization methods on the test instance, etc.
Extensions that implement
TestInstancePostProcessormust be registered at the class level, declaratively via a field of the test class, or programmatically via a static field of the test class.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. SeepostProcessTestInstance(Object, ExtensionContext)for further details.
-
-
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 voidpostProcessTestInstance(java.lang.Object testInstance, ExtensionContext context)Callback for post-processing the supplied test instance.-
Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
-
-
-
Method Detail
-
postProcessTestInstance
void postProcessTestInstance(java.lang.Object testInstance, ExtensionContext context) throws java.lang.ExceptionCallback for post-processing the supplied test instance.By default, the supplied
ExtensionContextrepresents the test class that's being post-processed. 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.Note: the
ExtensionContextsupplied to aTestInstancePostProcessorwill always return an emptyOptionalvalue fromgetTestInstance(). ATestInstancePostProcessorshould therefore only attempt to process the suppliedtestInstance.- Parameters:
testInstance- the instance to post-process; nevernullcontext- the current extension context; nevernull- Throws:
java.lang.Exception
-
-