I've just upgraded my projects to use Spring Boot 2.1.0 (before it was 2.0.x) and i have compilation WARNINGS:
[WARNING] Cannot find annotation method 'value()' in type 'org.junit.jupiter.api.extension.ExtendWith': class file for org.junit.jupiter.api.extension.ExtendWith not found
I can add dependency org.junit.jupiter / junit-jupiter-api to solve the warning, but I feel it's a 'hack'.
I don't want to see that warning (especially that my projects treat warnings like errors) and I don't want to pollute my projects with unnecessary dependencies.
i'm using Maven, but i can see someone had the same problem with Gradle https://www.reddit.com/r/java/comments/9sogxf/spring_boot_210_released_now_with_java_11_support/
Important note. Spring Boot 2.3. 0 includes junit5 as the default library for unit testing.
After few research I got to know that Spring-boot 2.4 onwards, JUnit4 has been removed.
If you use the spring-boot-starter-test 'Starter' (in the test scope ), you will find the following provided libraries: JUnit — The de-facto standard for unit testing Java applications.
JUnit 5 leverages features from Java 8 or later, like lambda functions, making tests more powerful and easier to maintain. JUnit 5 has added some very useful new features for describing, organizing, and executing tests. For instance, tests get better display names and can be organized hierarchically.
If you add the org.junit.jupiter:junit-jupiter-api
dependency to your project the warning will go away.
It shouldn't hurt, because it's only API jar and only in test scope.
If you are using the @SpringBootTest
to set classes=
:
@SpringBootTest(classes = {
MyAutoConfiguration.class,
MyAutoConfigurationIntegrationTest.TestContextConfiguration.class
})
the answer is alluded to in its api documentation:
Annotation that can be specified on a test class that runs Spring Boot based tests. Provides the following features over and above the regular Spring TestContext Framework:
Uses SpringBootContextLoader as the default ContextLoader when no specific @ContextConfiguration(loader=...) is defined.
Automatically searches for a @SpringBootConfiguration when nested @Configuration is not used, and no explicit classes are specified.
You can use @ContextConfiguration
which does not depend on Junit5's @ExtendsWith
:
@RunWith(SpringRunner.class)
@ContextConfiguration(loader = SpringBootContextLoader.class,
classes = {
MyAutoConfiguration.class,
MyAutoConfigurationIntegrationTest.TestContextConfiguration.class
})
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