spring-boot-starter-test with JUnit 5

A few additional notes to the ones mentioned by other contributors:

Using Spring Boot > 2.4.0

If you are using Spring Boot > 2.4.0, then there is nothing you have to do to use JUnit 5 Jupiter, because the spring-boot-starter-test library no longer includes the vintage-engine dependency (which transitively included JUnit 4), just include the starter dependency to the project and you’re good to go. Use the useJUnitPlatform() in the Gradle configuration.

Using 2.4.0 > Spring Boot > 2.2.0

If you use earlier versions, I’d suggest using a version higher than 2.2.0.RELEASE, which is where the Spring team added support for JUnit 5 Jupiter into the spring-boot-starter-test by default.

In these versions, the library included the Vintage Engine dependency too, which could be used to run JUnit 4 tests using the JUnit 5 Jupiter platform. If you don’t need to execute JUnit 4 tests, then the spring team suggests excluding org.junit.vintage:junit-vintage-engine (not just junit as indicated in the description):

testCompile('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage'
}

Here you would also need to configure the useJUnitPlatform() directive, of course.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)