Top Description Methods
org.junit.jupiter.api.extension

public Interface TestInstancePostProcessor

extends TestInstantiationAwareExtension
Annotations
@FunctionalInterface
@API
status:STABLE
since:5.0
Static Imports
org.apiguardian.api.API.Status.STABLE

TestInstancePostProcessor defines the API for Extensions that 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 TestInstancePostProcessor must 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 Extension for details on constructor requirements.

ExtensionContext Scope

As of JUnit Jupiter 5.12, this API participates in the TestInstantiationAwareExtension contract. Implementations of this API may therefore choose to override getTestInstantiationExtensionContextScope(ExtensionContext) to require a test-method scoped ExtensionContext. See postProcessTestInstance(Object, ExtensionContext) for further details.

Since
5.0
See Also
postProcessTestInstance(Object, ExtensionContext), TestInstancePreDestroyCallback, TestInstanceFactory, ParameterResolver

Method Summary

Modifier and TypeMethod and Description
public void
postProcessTestInstance(Object
the instance to post-process; never null
testInstance
,
ExtensionContext
the current extension context; never null
context
)

Callback for post-processing the supplied test instance.

Inherited from org.junit.jupiter.api.extension.TestInstantiationAwareExtension:
getTestInstantiationExtensionContextScope

Method Detail

postProcessTestInstanceback to summary
public void postProcessTestInstance(Object testInstance, ExtensionContext context) throws Exception

Callback for post-processing the supplied test instance.

By default, the supplied ExtensionContext represents the test class that's being post-processed. Extensions may override getTestInstantiationExtensionContextScope to return TEST_METHOD in order to change the scope of the ExtensionContext to the test method, unless the PER_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 provided Store instance.

Note

the ExtensionContext supplied to a TestInstancePostProcessor will always return an empty java.util.Optional value from getTestInstance(). A TestInstancePostProcessor should therefore only attempt to process the supplied testInstance.

Parameters
testInstance:Object

the instance to post-process; never null

context:ExtensionContext

the current extension context; never null