Last weekend, a new version of the Apache Maven Surefire-Plugin has been released:
The provider hosted by the @junitteam will be deprecated soon.
— Christian Stein (@sormuras) June 16, 2018
The Failsafe-Plugin has been updated as well. Both support JUnit 5 natively.
To make use of JUnit 5 in a Spring Boot 2 application, there’s not much todo. Here’s a gist of a POM that brings everything. See comments in the code. Basically all you have to do is overwrite the managed versions of the Surefire- and Failsafe-Plugins and then exclude the JUnit 4 dependency from Spring Boots Starter Test (and all other test related starters, i.e. security-starter-test). You’ll than declare both the JUnit 5 Jupiter Api and Engine, both in scope test. You could put the engine into the plugins dependency, but I couldn’t think of an aspect that’s improved by more cruft. Then, write unit and integration tests as shown (the later with annotated with
You’ll notice that only the Failsafe-Plugin has been declared. Spring Boots parent POM already takes care of the Surefire-Plugin.
And that’s all you need for Spring Boot 2 with JUnit 5.
Did you like this article? You can invite me on a coffee ☕️ if you like.