Interface TestTemplateInvocationContextProvider
-
- All Superinterfaces:
Extension
@API(status=STABLE, since="5.0") public interface TestTemplateInvocationContextProvider extends ExtensionTestTemplateInvocationContextProviderdefines the API forExtensionsthat wish to provide one or multiple contexts for the invocation of a@TestTemplatemethod.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:
supportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext)andprovideTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext). 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 aStreamofTestTemplateInvocationContextinstances. Otherwise, this provider is ignored for the execution of the current test template.A provider that has returned
truefrom itssupportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext)method is called active. When multiple providers are active for a test template method, theStreamsreturned by theirprovideTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext)methods will be chained, and the test template method will be invoked using the contexts of all active providers.Constructor Requirements
Consult the documentation in
Extensionfor details on constructor requirements.- Since:
- 5.0
- See Also:
TestTemplate,TestTemplateInvocationContext
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.util.stream.Stream<TestTemplateInvocationContext>provideTestTemplateInvocationContexts(ExtensionContext context)Provide invocation contexts for the test template method represented by the suppliedcontext.booleansupportsTestTemplate(ExtensionContext context)Determine if this provider supports providing invocation contexts for the test template method represented by the suppliedcontext.
-
-
-
Method Detail
-
supportsTestTemplate
boolean supportsTestTemplate(ExtensionContext context)
Determine if this provider supports providing invocation contexts for the test template method represented by the suppliedcontext.- Parameters:
context- the extension context for the test template method about to be invoked; nevernull- Returns:
trueif this provider can provide invocation contexts- See Also:
provideTestTemplateInvocationContexts(org.junit.jupiter.api.extension.ExtensionContext),ExtensionContext
-
provideTestTemplateInvocationContexts
java.util.stream.Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context)
Provide invocation contexts for the test template method represented by the suppliedcontext.This method is only called by the framework if
supportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext)previously returnedtruefor the sameExtensionContext. Thus, this method must not return an emptyStream.The returned
Streamwill be properly closed by callingBaseStream.close(), making it safe to use a resource such asFiles.lines().- Parameters:
context- the extension context for the test template method about to be invoked; nevernull- Returns:
- a
StreamofTestTemplateInvocationContextinstances for the invocation of the test template method; nevernullor empty - See Also:
supportsTestTemplate(org.junit.jupiter.api.extension.ExtensionContext),ExtensionContext
-
-