Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot convert from Class<SpringRunner> to Class<? extends Runner>

Tags:

java

junit

spring

I am getting the below compiler error:

Type mismatch: cannot convert from Class<SpringRunner> to Class<? extends Runner>

From this code:

import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@DataMongoTest
public class ReservationEntityTest {

I don't understand the error Class<SpringRunner> has SpringRunner that extends Runner.
What am I missing?.

like image 835
civilian Avatar asked Sep 11 '25 10:09

civilian


1 Answers

The actual response was the one of @M. Demiun in the comments;

"Remove your junit dependency from the pom.xml. You are using an ancient version. The spring-boot-starter-test includes all dependencies needed. I would even suggest to remove the @RunWith and use the @Test from JUnit5 (the @DataMongoTest already shouldinclude the @ExtendWith from JUnit5."

like image 83
civilian Avatar answered Sep 14 '25 00:09

civilian