ParameterResolver defines the API for Extensions
that wish to dynamically resolve arguments for parameters
at runtime.
If a constructor for a test class or a
@Test,
@BeforeEach,
@AfterEach,
@BeforeAll, or
@AfterAll method declares a parameter,
an argument for the parameter must be resolved at runtime by a
ParameterResolver.
By default, when the methods in this interface are called for a test class
constructor, the supplied ExtensionContext represents the test
class that's about to be instantiated. 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.
Consult the documentation in Extension for details on
constructor requirements.
ExtensionContext ScopeAs 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.
supportsParameter(ParameterContext, ExtensionContext), resolveParameter(ParameterContext, ExtensionContext), ParameterContext, TestInstanceFactory, TestInstancePostProcessor, TestInstancePreDestroyCallback
| Modifier and Type | Method and Description |
|---|---|
| public @Nullable Object | Returns: the resolved argument for the parameter; may only benull if the
parameter type is not a primitivethe context for the parameter for which an argument should
be resolved; never parameterContext, ExtensionContext nullthe extension context for the extensionContext)Executable
about to be invoked; never nullResolve an argument for the |
| public boolean | Returns: true if this resolver can resolve an argument for the parameterthe context for the parameter for which an argument should
be resolved; never parameterContext, ExtensionContext nullthe extension context for the extensionContext)Executable
about to be invoked; never nullDetermine if this resolver supports resolution of an argument for the
|
| resolveParameter | back to summary |
|---|---|
| public @Nullable Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException Resolve an argument for the This method is only called by the framework if The
| |
| supportsParameter | back to summary |
|---|---|
| public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException Determine if this resolver supports resolution of an argument for the
The
| |