Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "TestEngine with ID 'junit-vintage' failed to discover tests" with Spring Boot 2.2

I have a simple app using Spring Boot and Junit 5:

  • When using Spring Boot 2.1 (e.g, 2.1.8 or 2.1.12), my unit tests run smoothly

  • When using Spring Boot 2.2 (e.g., 2.2.2.RELEASE or 2.3.2.RELEASE) my unit tests fail with error message

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project XXX: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Projets\workspace\XXX\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] TestEngine with ID 'junit-vintage' failed to discover tests
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] TestEngine with ID 'junit-vintage' failed to discover tests
[ERROR]         at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:656)

I am using Maven 3.6.1, JDK 1.8, JUnit 5.6.0 and JUnit platform 1.6.0. I exclude the dependency on junit:junit from spring-boot-starter-test, so that I have no JUnit 4 artifacts left in the dependency tree. Note that both Spring Boot 2.2 and 2.3 use maven-surefire-plugin 2.22.2, so my problem does not originate from any regression of the maven-surefire-plugin.

Should I stick to Spring Boot 2.1 in order to have my unit test working?

Thanks in advance for your help.

like image 236
Ivan dal Bosco Avatar asked Jan 24 '20 16:01

Ivan dal Bosco


3 Answers

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> 
like image 71
Ivan dal Bosco Avatar answered Dec 11 '22 06:12

Ivan dal Bosco


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> 
like image 26
Kashish Bhatia Avatar answered Dec 11 '22 05:12

Kashish Bhatia


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")
    }
}
like image 29
Mircea Stanciu Avatar answered Dec 11 '22 05:12

Mircea Stanciu