I am confused about the class SpringRunner.
From Stackoverflow and google did understand that SpringRunner and SpringJunit4ClassRunner are one and the same.
@RunWith(SpringRunner.class)
My understanding of this class is :
@RunWithWith Junit5 and spring boot is this class no longer required ?
If yes what should we be using in a spring boot and Junit5 environment then ?
From the reference document
If you are using JUnit 4, don’t forget to also add @RunWith(SpringRunner.class) to your test, otherwise the annotations will be ignored. If you are using JUnit 5, there’s no need to add the equivalent @ExtendWith(SpringExtension.class) as @SpringBootTest and the other @…Test annotations are already annotated with it.
With Junit5 and spring boot is this class no longer required?
The annotation @RunWith(SpringRunner.class) is no longer required, you can delete it.
Additionally, if you use only Junit5, it is recommended to exclude Junit4:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With