Error “TestEngine with ID ‘junit-vintage’ failed to discover tests” with Spring Boot 2.2
Introduction:
This error typically occurs when using Spring Boot 2.2 and the JUnit 4 test framework with the ‘junit-vintage’ engine.
Overview:
The issue arises from a compatibility problem between Spring Boot 2.2 and the JUnit 4 framework when trying to run tests using the ‘junit-vintage’ engine.
Problem:
The ‘TestEngine with ID ‘junit-vintage’ failed to discover tests’ error message is displayed when attempting to execute JUnit 4 tests in Spring Boot 2.2.
Solution:
To resolve this error, consider upgrading your tests to JUnit 5 or modifying the test configuration to work with JUnit 4 in Spring Boot 2.2. Alternatively, you can also try excluding the ‘junit-vintage’ engine from the test environment to prevent this error from occurring.
Key points to address:
– Check the version compatibility of JUnit Vintage with Spring Boot 2.2
– Verify that the necessary dependencies for JUnit Vintage are correctly configured in the Spring Boot project
– Ensure that the test classes are annotated properly and follow the correct package structure
– Check for any configuration issues or conflicts in the testing setup
– Look for any specific error messages or stack traces that could provide more insight into the root cause of the issue
– TestEngine with ID ‘junit-vintage’ failed to discover tests
Explain the Core Concept:
This error message typically occurs in Spring Boot 2.2 when there is a compatibility issue with the JUnit version being used.
The junit-vintage TestEngine is used to run JUnit 4 tests in JUnit 5. When this error occurs, it means that Spring Boot is not able to discover any tests using the vintage engine, which could be due to a mismatch in versions or misconfiguration.
Different Solutions with code samples:
1. Update the dependencies in your `pom.xml` to use newer versions of JUnit and Spring Boot:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.2.5.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</dependency>
2. You can also exclude the vintage engine from the tests by adding the following exclusions to your `@SpringBootTest` annotation:
@SpringBootTest(exclude = {JupiterEngine.class})
Conclusion:
Updating the dependencies to newer versions and excluding the vintage engine from the tests should resolve the error “TestEngine with ID ‘junit-vintage’ failed to discover tests” in Spring Boot 2.2.