Junit5 with spring-boot 1.5
Asked Answered
T

1

18

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.

Taker answered 29/12, 2017 at 8:3 Comment(0)
R
26

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.

Rhymester answered 30/12, 2017 at 6:1 Comment(2)
If doing a full conversion to JUnit5, remove JUnit4 with: testCompile('org.springframework.boot:spring-boot-starter-test') { exclude group: 'junit', module: 'junit' }Demmy
Could you please share the instructions instead of posting a link? Links may easily break, especially if you're linking a github readmePortal

© 2022 - 2024 — McMap. All rights reserved.