Error TestEngine with ID 'junit-vintage' failed to discover tests with Spring Boot 2.2
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
When working with Spring Boot 2.2, you may encounter the error message: "TestEngine with ID 'junit-vintage' failed to discover tests". This issue often arises due to inconsistencies in JUnit dependencies, especially when migrating or updating the project. Below, I provide a comprehensive overview of the problem, its causes, and solutions, with technical explanations and examples where relevant.
Understanding the Error
What is JUnit Vintage?
JUnit is a widely used framework for testing in Java. It comes in different versions, notably JUnit 4 and JUnit 5. JUnit 5 has introduced a new architecture, separating the testing model into multiple modules. One prominent feature is the JUnit Platform, which can run tests written with various testing frameworks, including JUnit 4 — for this, JUnit Vintage TestEngine is used.
Error Explanation
The error "TestEngine with ID 'junit-vintage' failed to discover tests" indicates that the junit-vintage-engine is active in the project but unable to find tests that it recognizes (JUnit 4 tests). This often happens when:
- The JUnit 4 dependency is removed or missing.
- The testing framework is not configured properly.
- The project mix-matches different versions of JUnit setting.
Common Causes
- Inconsistent Dependencies:
- Missing
junit-vintage-enginedependency. - Presence of both JUnit 4 and Junit 5 dependencies without proper configuration.
- Migration Issues:
- Projects migrating from JUnit 4 to JUnit 5 without removing outdated dependencies.
- Misconfiguration in
build.gradleorpom.xml:- Incorrect Maven or Gradle setup leading to engine failures.
Example Scenario
Consider a Spring Boot 2.2 project where tests are failing to execute due to this error. This occurs after an attempted migration from JUnit 4 to JUnit 5. Previously, the project had tests written using JUnit 4, but recent templates and some newer tests were written using JUnit 5.
build.gradle Misconfiguration
Before migration:
After inappropriate migration:
pom.xml Misconfiguration
Before migration:
After inappropriate migration:
Resolving the Error
Recommended Configuration
For projects that need backward compatibility (using both JUnit 4 and JUnit 5):
With Gradle
With Maven
Removing Vintage Support (JUnit 5 Only)
If you're moving completely to JUnit 5 and no longer need JUnit 4:
With Gradle
With Maven
Key Points Summary
| Cause | Explanation | Solution |
| Inconsistent Dependencies | Missing or conflicting JUnit versions. | Ensure correct dependencies for test or remove conflicting ones. |
| Migration Issues | JUnit 4 and JUnit 5 being used improperly together. | Tailor configuration to support both frameworks or migrate fully to JUnit 5. |
| Misconfiguration | Errors in pom.xml or build.gradle settings. | Review and correct build scripts to match the intended JUnit version(s). |
By following these guidelines, the error "TestEngine with ID 'junit-vintage' failed to discover tests" should be resolvable, allowing for a smooth and effective testing experience within the Spring Boot 2.2 environment.

