@API(value=Experimental) public interface TestTemplateInvocationContextProvider extends Extension
TestTemplateInvocationContextProvider defines the API for
Extensions that wish to provide one or multiple contexts
for the invocation of a
@TestTemplate method.
This extension point makes it possible to execute a test template in different contexts — for example, with different parameters, by preparing the test class instance differently, or multiple times without modifying the context.
This interface defines two methods: supports(org.junit.jupiter.api.extension.ContainerExtensionContext) and
provide(org.junit.jupiter.api.extension.ContainerExtensionContext). The former is called by the framework to determine whether
this extension wants to act on a test template that is about to be executed.
If so, the latter is called and must return a Stream of
TestTemplateInvocationContext instances. Otherwise, this provider is
ignored for the execution of the current test template.
A provider that has returned true from its supports(org.junit.jupiter.api.extension.ContainerExtensionContext)
method is called active. When multiple providers are active for a
test template method, the Streams returned by their provide(org.junit.jupiter.api.extension.ContainerExtensionContext)
methods will be chained, and the test template method will be invoked using
the contexts of all active providers.
Implementations must provide a no-args constructor.
TestTemplate,
TestTemplateInvocationContext| Modifier and Type | Method and Description |
|---|---|
java.util.stream.Stream<TestTemplateInvocationContext> |
provide(ContainerExtensionContext context)
Provide invocation contexts
for the test template method represented by the supplied
context. |
boolean |
supports(ContainerExtensionContext context)
Determine if this provider supports providing invocation contexts for the
test template method represented by the supplied
context. |
boolean supports(ContainerExtensionContext context)
context.context - the container extension context for the test template
method about to be invoked; never nulltrue if this provider can provide invocation contextsprovide(org.junit.jupiter.api.extension.ContainerExtensionContext),
ContainerExtensionContextjava.util.stream.Stream<TestTemplateInvocationContext> provide(ContainerExtensionContext context)
context.
This method is only called by the framework if supports(org.junit.jupiter.api.extension.ContainerExtensionContext) has
previously returned true for the same
ContainerExtensionContext. Thus, it must not return an empty
Stream.
The returned Stream will be properly closed by calling
BaseStream.close(), making it safe to use a resource such as
Files.lines().
context - the container extension context for the test template
method about to be invoked; never nullStream of TestTemplateInvocationContext
instances for the invocation of the test template method; never null
or emptysupports(org.junit.jupiter.api.extension.ContainerExtensionContext),
ContainerExtensionContext