JUnit 5 extension for Spring

In order to integrate the spring-test capabilities into JUnit 5's Jupiter programming model, SpringExtension has been developed. This extension is part of the spring-test module, as of Spring 5. Let's see several examples of JUnit 5 and Spring 5 together.

Let’s suppose we want to make an integration in-container test of the Spring application described in the former section, made up of three classes: MySpringApplication, MessageComponent, and MessageService. As we have learned, in order to implement a Jupiter test against this application, we need to make the following steps:

  1. Annotate our test class with @ContextConfiguration to specify which ApplicationContext needs to be loaded.
  2. Annotate our test class with ...

Get Mastering Software Testing with JUnit 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.