Spring Boot
JUnit Vintage
TestEngine
Testing Error
Spring Boot 2.2

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

  1. Inconsistent Dependencies:
    • Missing junit-vintage-engine dependency.
    • Presence of both JUnit 4 and Junit 5 dependencies without proper configuration.
  2. Migration Issues:
    • Projects migrating from JUnit 4 to JUnit 5 without removing outdated dependencies.
  3. Misconfiguration in build.gradle or pom.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:

gradle
dependencies {
    testImplementation 'junit:junit:4.12'
}

After inappropriate migration:

gradle
1dependencies {
2    testImplementation 'junit:junit:4.12'
3    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.0'
4}

pom.xml Misconfiguration

Before migration:

xml
1<dependency>
2    <groupId>junit</groupId>
3    <artifactId>junit</artifactId>
4    <version>4.12</version>
5    <scope>test</scope>
6</dependency>

After inappropriate migration:

xml
1<dependency>
2    <groupId>junit</groupId>
3    <artifactId>junit</artifactId>
4    <version>4.12</version>
5    <scope>test</scope>
6</dependency>
7<dependency>
8    <groupId>org.junit.jupiter</groupId>
9    <artifactId>junit-jupiter-api</artifactId>
10    <version>5.6.0</version>
11    <scope>test</scope>
12</dependency>

Resolving the Error

For projects that need backward compatibility (using both JUnit 4 and JUnit 5):

With Gradle

gradle
1dependencies {
2    testImplementation 'org.junit.jupiter:junit-jupiter:5.6.0'
3    testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.6.0'
4}
5
6// Ensure the use of the JUnit platform
7test {
8    useJUnitPlatform()
9}

With Maven

xml
1<dependency>
2    <groupId>org.junit.jupiter</groupId>
3    <artifactId>junit-jupiter-engine</artifactId>
4    <version>5.6.0</version>
5    <scope>test</scope>
6</dependency>
7<dependency>
8    <groupId>org.junit.vintage</groupId>
9    <artifactId>junit-vintage-engine</artifactId>
10    <version>5.6.0</version>
11    <scope>test</scope>
12</dependency>

Removing Vintage Support (JUnit 5 Only)

If you're moving completely to JUnit 5 and no longer need JUnit 4:

With Gradle

gradle
1dependencies {
2    testImplementation 'org.junit.jupiter:junit-jupiter:5.6.0'
3}
4
5test {
6    useJUnitPlatform()
7}

With Maven

xml
1<dependency>
2    <groupId>org.junit.jupiter</groupId>
3    <artifactId>junit-jupiter</artifactId>
4    <version>5.6.0</version>
5    <scope>test</scope>
6</dependency>

Key Points Summary

CauseExplanationSolution
Inconsistent DependenciesMissing or conflicting JUnit versions.Ensure correct dependencies for test or remove conflicting ones.
Migration IssuesJUnit 4 and JUnit 5 being used improperly together.Tailor configuration to support both frameworks or migrate fully to JUnit 5.
MisconfigurationErrors 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.


Course illustration
Course illustration

All Rights Reserved.