...

/

Test Templates

Test Templates

Let's learn how to use test templates in JUnit 5.

We discussed repeated tests and parameterized tests in previous chapters. Methods annotated with @RepeatedTest and @ParameterizedTest aren’t the actual executed tests, but templates for other tests. JUnit 5 has a specific annotation, org.junit.jupiter.api.TestTemplate, that makes a test method a test template.

Creating test templates

To create test templates, we need to create custom extensions that implement the TestTemplateInvocationContextProvider interface. This interface has two methods:

  • The boolean supportsTestTemplate(ExtensionContext context) method checks if
...