Run Unit Test using JUnit 5 with Apache Maven

In my previous tutorial, I talked about the Apache Maven’s Maven Surefire Plugin plugin to run Unit Test in Maven projects. I used JUnit 4 in the example of this tutorial. If I now upgrade my JUnit library from version 4 to version 5 in that example by changing the dependency of JUnit for version 5 in the pom.xml file:

and correct the CalculationTest class properly:

then when you right click on the project and select Run As and select Maven test, you will see the error when running as follows:

What are the causes? That’s because the current Maven Surefire Plugin default of the Apache Maven version that I’m using is not fully supported for JUnit version 5.

To overcome this error, you explicitly declare Maven Surefire Plugin plugin in the pom.xml file with version 2.22.0 or above as follows:

At this point, if you run “mvn test”, you will not see the error again:

Add Comment