There is a newer version available.
For the latest stable version, please use JUnit 6.0.1!

Test Instance Post-processing

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.

For a concrete example, consult the source code for the MockitoExtension and the SpringExtension.

Accessing the test-scoped ExtensionContext

You may override the getTestInstantiationExtensionContextScope(…​) method to return TEST_METHOD to make test-specific data available to your extension implementation or if you want to keep state on the test method level.