Shades88
Shades88

Reputation: 8360

junit test cases not executing when spring boot application migrated from 2.1.5 to 2.4

I had an application running in spring-boot 2.1.5, migrated that to version 2.4.0. None of my tests are executing now. When I hit mvn clean test it always says 0 tests executed.

I noticed that spring boot 2.4.0 comes bundled with junit.jupiter library. My 2.1.5 tests are using junit:junit:4.4 dependency.

How to retain my old test cases without migrating to junit.jupiter?

Upvotes: 1

Views: 638

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116111

This is covered in the release notes for Spring Boot 2.4:

If you do not want to migrate your tests to JUnit 5 and wish to continue using JUnit 4, add a dependency on the Vintage Engine, as shown in the following example for Maven:

<dependency>
   <groupId>org.junit.vintage</groupId>
   <artifactId>junit-vintage-engine</artifactId>
   <scope>test</scope>
   <exclusions>
       <exclusion>
           <groupId>org.hamcrest</groupId>
           <artifactId>hamcrest-core</artifactId>
       </exclusion>
   </exclusions>
</dependency>

If you are using Gradle, the equivalent configuration is shown in the following example:

testImplementation("org.junit.vintage:junit-vintage-engine") {
   exclude group: "org.hamcrest", module: "hamcrest-core"
}

Upvotes: 2

Related Questions