Junit5: JUnit Jupiter 5.6.0 tests do not run with Maven Surefire and IntelliJ IDEA

Created on 30 Jan 2020  Â·  11Comments  Â·  Source: junit-team/junit5

Trying to upgrade JUnit Jupiter from 5.5.2( where everything is running fine) to 5.6.0 for Java (Spring Boot) project. Both Maven Surefire plugin (v 2.22.2) and IntelliJ IDEA (Ultimate v 2019.3) doesn't detect or run the tests

Steps to reproduce

Sample Code

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class SampleTest {

    @Test public void testSample(){
        Assertions.assertEquals(4/2, 2);
    }
}

Context

  • Used versions : Jupiter v5.6.0
  • Build Tool/IDE: maven surefire plugin v2.22.2 and Intellij IDEA Ultimate 2019.3

Screenshot 2020-01-30 at 9 02 02 PM
Screenshot 2020-01-30 at 9 01 41 PM

invalid question

Most helpful comment

There was some activity about this one on twitter, see https://twitter.com/hakandamar/status/1243120351791497217

Based on that example, here is the proper way of avoiding mixed version of JUnit on the classpath: https://github.com/snicoll-scratches/test-junit/commit/d5a05e263174b0f6b91e5d597c0b437b4da87e82

In this particular cases, only 3 dependencies were overridden but the rest was still managed by Spring Boot. As a result the following dependencies still had the wrong versions:

org.junit.jupiter:junit-jupiter:jar:5.5.2:test
org.junit.platform:junit-platform-commons:jar:1.5.2:test
org.junit.platform:junit-platform-engine:jar:1.5.2:test

Making sure consistent versions are used fixes the problem.

TL;DR: do not override individual modules, this will lead to mixed versions on the classpath and unpredictable result. If you are using spring-boot-starter-parent, the commit I've just shared is the proper way of overriding a version. If you are not, please import junit-bom again.

@lintong that example of yours is not accurate, it should use the bom instead.

All 11 comments

How did you physically _upgrade_ your Spring Boot application to JUnit Jupiter 5.6?

Did you do something similar to the following in your Maven POM?

<properties>
    <junit-jupiter.version>5.6.0</junit-jupiter.version>
</properties>

See also: https://stackoverflow.com/questions/54598484/gradle-5-junit-bom-and-spring-boot-incorrect-versions/54605523#54605523

No, I have explicit dependency added to the project which was using version 5.5.2 earlier
<dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.6.0</version> <scope>test</scope> </dependency>

Attempting to override Spring Boot's dependency management via an explicit dependency declaration like that is not supported. Please see the aforementioned Stack Overflow (SO) question for further details and links to the corresponding Spring Boot documentation.

In light of that, I am closing this issue; however, if you still have issues after following the advice from the SO answer, I'd recommend that you post a new question SO.

Cheers

I'm using JUnit along with Spring Boot, but without the corresponding Spring Boot parent. Simplified POM:

<properties>
    <spring.boot.version>2.2.4.RELEASE</spring.boot.version>
    <junit-jupiter.version>5.5.2</junit-jupiter.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>${spring.boot.version}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter</artifactId>
        <version>${junit-jupiter.version}</version>
    </dependency>
</dependencies>

<plugins>
    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>${spring.boot.version}</version>
    </plugin>
</plugins>

The setup is fine unless I bump JUnit to 5.6.0, then no tests are executed via Surefire.

Is there anything else I have to configure?

@beatngu13, could you perhaps provide us a simplified sample application that we can experiment with?

I can reproduce it in my multi-module Maven project, but I realized it's not straightforward to do so with a minimal setup. Will try to come up with a sample project, don't bother until then.

@prasadthotakura,, the spring boot bom is overriding some of the dependencies pulled in transitively by Jupiter. Either wait for the Spring guys to do the upgrade or use something similar to the following config in your reactor pom:

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.2.4.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>

        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.6.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.6.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-commons</artifactId>
            <version>1.6.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-engine</artifactId>
            <version>1.6.0</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
            </plugin>
        </plugins>
    </build>

There was some activity about this one on twitter, see https://twitter.com/hakandamar/status/1243120351791497217

Based on that example, here is the proper way of avoiding mixed version of JUnit on the classpath: https://github.com/snicoll-scratches/test-junit/commit/d5a05e263174b0f6b91e5d597c0b437b4da87e82

In this particular cases, only 3 dependencies were overridden but the rest was still managed by Spring Boot. As a result the following dependencies still had the wrong versions:

org.junit.jupiter:junit-jupiter:jar:5.5.2:test
org.junit.platform:junit-platform-commons:jar:1.5.2:test
org.junit.platform:junit-platform-engine:jar:1.5.2:test

Making sure consistent versions are used fixes the problem.

TL;DR: do not override individual modules, this will lead to mixed versions on the classpath and unpredictable result. If you are using spring-boot-starter-parent, the commit I've just shared is the proper way of overriding a version. If you are not, please import junit-bom again.

@lintong that example of yours is not accurate, it should use the bom instead.

@beatngu13 you should include junit-bom rather than a single artifact. This is the same issue as above where one module uses 5.6 and the rest still use 5.5.2. You should also include JUnit's BOM before spring-boot-dependencies since it also has an opinion on the JUnit version to use.

Related Maven POM/BOM quiz by @aalmiray https://twitter.com/aalmiray/status/1243119645151952897 -- I learned a lot today.

@snicoll thx for your help!

@sormuras oh boy, I thought I know Maven … 🙈

Was this page helpful?
0 / 5 - 0 ratings