I have a spring-boot application which uses spring-boot version 1.5.9.RELEASE
. To test this application I want to use junit-jupiter version 5.0.2
.
For simple service tests it works without any problems. But when it comes to testing rest endpoints, I am failing. The reason is the @RunWith(SpringRunner.class)
annotation, which I used with junit4 to wire the everything together.
Is there a SpringRunner
for junit5 before spring-boot 2?
Update
I just stumbled over an article on how to run JUnit5 tests. Point 4 looks like a promising start.
JUnit 5 tests will run with Java 8 or above.
By default, spring-boot-starter-test dependency imports the junit 4 dependencies into Spring boot application.
JUnit 5 is 10x slower than JUnit 4 #880.
Anatomy of the Spring Boot Starter Test This starter includes Spring-specific dependencies and dependencies for auto-configuration and a set of testing libraries. This includes JUnit, Mockito, Hamcrest, AssertJ, JSONassert, and JsonPath.
To migrate from JUnit 4 to JUnit 5 you can replace @RunWith(SpringRunner.class)
with @ExtendWith(SpringExtension.class)
.
Unfortunately, spring-boot version 1.5.9-RELEASE
is based on Spring 4 and the SpringExtension
is only available since Spring 5.
However, there is a solution since it's possible to use JUnit 5 and SpringExtension
in Spring 4 by using spring-test-junit5
. Just check the instructions for setting up the dependencies.
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