O'Reilly logo

Mastering Software Testing with JUnit 5 by Boni García

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Test templates

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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required