Last weekend, a new version of the Apache Maven Surefire-Plugin has been released:
Kudos to @BenediktRitter and @tibor17 for making native #JUnit5 support in @ASFMavenProject Surefire 2.22.0 happen! ✅
Updated the #JUnit Maven samples via https://t.co/IOxKdS57Hk
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 @ExtendWith(SpringExtension.class)
).
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.
One comment
@DisplayName(“Example Service should work!”)
void exampleServiceShouldWork() {
🙂
I would prefer Spock definetely
4 Trackbacks/Pingbacks
[…] >> Maven: Use JUnit 5 with Spring Boot for Unit and Integration Tests [info.michael-simons.eu] […]
[…] Maven: Use JUnit 5 with Spring Boot for unit and integration tests is a practical blog post that helps you run your unit and integration tests with Maven when you are using Spring Boot. […]
[…] I was following this tutorial but was required to add a few things to my POM because Intellij wasn’t picking up the Jupiter runner correctly: https://info.michael-simons.eu/2018/06/18/maven-use-junit-5-with-spring-boot-for-unit-and-integratio… […]
[…] https://info.michael-simons.eu/2018/06/18/maven-use-junit-5-with-spring-boot-for-unit-and-integratio… as a starting point I recommend to add the jupiter-engine as an explicit […]
Post a Comment