Where is @RunWith in latest Spring Boot releases?

Users of latest Spring Boot releases starting from 2.4.0 might see compilation errors while using @RunWith(SpringRunner.class)

java: cannot find symbol
symbol: class RunWith

Starting with Spring Boot release 2.4.0, JUnit 5’s vintage engine has been removed from spring-boot-starter-test. The vintage engine allows tests written with JUnit 4 to be run by JUnit 5. 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>

Starting with Spring Boot Release 2.2 Junit 5 was provided by default in spring-boot-starter-test. They also provided Junit 5’s Vintage engine to support Junit 4 based test classes. Now with Spring Boot version 2.4.0 they dropped this Vintage engine. At this point migrating to Junit 5 is a good idea.

Note: With Junit5 just removing the @RunWith annotation should work fine.

%d bloggers like this: