Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUnit Jupiter 5.6.0 tests do not run with Maven Surefire and IntelliJ IDEA #2169

Closed
prasadthotakura opened this issue Jan 30, 2020 · 11 comments

Comments

@prasadthotakura
Copy link

prasadthotakura commented Jan 30, 2020

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

@sbrannen
Copy link
Member

sbrannen commented Jan 31, 2020

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

@prasadthotakura
Copy link
Author

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>

@sbrannen
Copy link
Member

sbrannen commented Feb 3, 2020

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

@beatngu13
Copy link

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?

@sbrannen
Copy link
Member

sbrannen commented Feb 3, 2020

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

@beatngu13
Copy link

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.

@lintong
Copy link

lintong commented Mar 3, 2020

@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>

@snicoll
Copy link

snicoll commented Mar 26, 2020

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: snicoll-scratches/test-junit@d5a05e2

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.

@snicoll
Copy link

snicoll commented Mar 26, 2020

@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.

@sormuras
Copy link
Member

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

@beatngu13
Copy link

@snicoll thx for your help!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants