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

public Interface TestInstancePreConstructCallback

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

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.

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 preConstructTestInstance(TestInstanceFactoryContext, ExtensionContext) for further details.

Since
5.9
See Also
TestInstancePreDestroyCallback, TestInstanceFactory, ParameterResolver

Method Summary

Modifier and TypeMethod and Description
public void
preConstructTestInstance(TestInstanceFactoryContext
the context for the test instance about to be instantiated; never null
factoryContext
,
ExtensionContext
the current extension context; never null
context
)

Callback invoked prior to test instances being constructed.

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

Method Detail

preConstructTestInstanceback to summary
public 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 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.

Parameters
factoryContext:TestInstanceFactoryContext

the context for the test instance about to be instantiated; never null

context:ExtensionContext

the current extension context; never null