Error "TestEngine with ID 'junit-vintage' failed to discover tests" with Spring Boot 2.2
I found the error. The dependency on spring-boot-starter-test
brings a dependency on junit-vintage-engine
. The latter must be excluded:
<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>
Adding the following dependency explicitly to upgrade junit-vintage-engine
resolves the issue:
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
</dependency>
In my case (GRADLE and Spring Boot 2.x.x), adding exclusion for vintage worked
configurations {
all {
exclude(group = "junit", module = "junit")
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
}
For the reported error in the question or the below error, both relate to the same problem.
java.lang.NoClassDefFoundError: junit/runner/Version
This error occurs if the project excludes or not include JUnit 4
when it depends on spring-boot-starter-test
. The spring-boot-starter-test
depends on junit-vintage-engine
by default. To resolve this issue either we have to exclude junit-vintage-engine
Or should not depend on spring-boot-starter-test
.
testImplementation('org.springframework.boot:spring-boot-starter-test:2.2.2.RELEASE') {
exclude group: 'junit'
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation('org.junit.jupiter:junit-jupiter-api:5.5.2')
testImplementation('org.junit.jupiter:junit-jupiter-engine:5.5.2')
testImplementation('org.junit.jupiter:junit-jupiter-params:5.5.2')