Junit5: How can I use JUnit 5 with Spring 5?

Created on 4 Dec 2016  路  2Comments  路  Source: junit-team/junit5

My Email is [email protected]

question

Most helpful comment

Please note that questions like this are more suitable for Stack Overflow using the junit5 tag.

In any case, it's quite easy to use Spring with JUnit 5 via the SpringExtension for JUnit Jupiter.

If you are using Spring Framework 5.0 milestone releases, the SpringExtension is available in the spring-test JAR. If you're using Spring Framework 4.3, the SpringExtension is only available if you build the spring-test-junit5 JAR yourself from my repository: https://github.com/sbrannen/spring-test-junit5

Then, to use Spring with JUnit 5 (i.e., in JUnit Jupiter tests), simply register the extension like this: @ExtendWith(SpringExtension.class).

As an alternative, you can use one of the @SpringJUnitJupiterConfig or @SpringJUnitJupiterWebConfig composed annotations to simplify matters.

Regards,

Sam (author of the Spring TestContext Framework)

All 2 comments

Please note that questions like this are more suitable for Stack Overflow using the junit5 tag.

In any case, it's quite easy to use Spring with JUnit 5 via the SpringExtension for JUnit Jupiter.

If you are using Spring Framework 5.0 milestone releases, the SpringExtension is available in the spring-test JAR. If you're using Spring Framework 4.3, the SpringExtension is only available if you build the spring-test-junit5 JAR yourself from my repository: https://github.com/sbrannen/spring-test-junit5

Then, to use Spring with JUnit 5 (i.e., in JUnit Jupiter tests), simply register the extension like this: @ExtendWith(SpringExtension.class).

As an alternative, you can use one of the @SpringJUnitJupiterConfig or @SpringJUnitJupiterWebConfig composed annotations to simplify matters.

Regards,

Sam (author of the Spring TestContext Framework)

If you're using Spring Framework 4.3, the SpringExtension is only available if you build the spring-test-junit5 JAR yourself from my repository: https://github.com/sbrannen/spring-test-junit5

Or you can use jitpack.io.

Was this page helpful?
0 / 5 - 0 ratings