A @TestTemplate method is not a regular test case but a template for test cases. Method annotated like this will be invoked multiple times, depending on the invocation context returned by the registered providers. Thus, test templates are used together with a registered TestTemplateInvocationContextProvider extension.
Let see a simple example of a test template. In the following snippet, we can see a method annotated with @TestTemplate, and also declaring an extension of the type MyTestTemplateInvocationContextProvider:
package io.github.bonigarcia;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.api.extension.ExtendWith;
class TemplateTest {
@TestTemplate
@ExtendWith(MyTestTemplateInvocationContextProvider.class)
void testTemplate(String parameter) {
System.out.println(parameter);
}
}
The required provided implements the Jupiter...