REW
REW

Reputation: 776

JUnit is fine via command line, fails in IntelliJ

I'm working in a project that is new to me, but has been around for a while.

I try running the unit tests from the terminal with mvn clean test and the unit tests run as expected.

Unfortunately for me, I really could use some debugging help from IntelliJ on some of these unit tests. Any time I try to run a unit test from IntelliJ, I get this output:

Internal Error occurred.

org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-vintage' failed to discover tests

Caused by: org.junit.platform.commons.JUnitException: Unsupported version of junit:junit: 3.8.1. Please upgrade to version 4.12 or later.

According to pom.xml, I'm using JUnit 5.7.0, Mockito 3.7.7, and (since some results I've googled suggest it could be a Spring Boot issue) no sign of Spring Boot. I've also tried including junit-vintage, since it is mentioned in the output, but that seems to make no difference, either.

Upvotes: 3

Views: 2361

Answers (3)

Amit
Amit

Reputation: 1

Can try few below-mentioned steps to fix the issue:

  1. Run mvn dependency:tree and check for the transitive dependencies for junit:junit if any.

  2. Check in parent pom.xml for junit-addons (if exists) and exclude junit from it.


<dependency>
    <groupId>junit-addons</groupId>
    <artifactId>junit-addons</artifactId>
    <version>1.4</version>
    <exclusions>
        <!-- Note: avoid junit 3 as a dependency -->
        <exclusion>
            <artifactId>junit</artifactId>
            <groupId>junit</groupId>
        </exclusion>
    </exclusions>
    <scope>test</scope>
</dependency>

Upvotes: 0

REW
REW

Reputation: 776

It's the old StackOverflow curse -- search for a solution for hours and hours, get nowhere; post on StackOverflow, even helpful people don't know what the issue is, but now I can find the answer from Google in a snap.

Despite my having added junit-vintage to my project previously, apparently I was not adding the correct artifact, or version, or something. Because that's the solution here.

Here is a link to the discussion that led me to the answer -- add this dependency:

    <dependency> 
        <groupId>org.junit.vintage</groupId>
        <artifactId>junit-vintage-engine</artifactId>
        <version>5.2.0</version>
        <scope>test</scope>
    </dependency>

Upvotes: 1

Stefan Birkner
Stefan Birkner

Reputation: 24560

Can you try to add

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.13.1</version>
</dependency>

to your pom.xml. Maybe you have junit only as a transitive dependency and therefore 3.8.1 is chosen.

Upvotes: 0

Related Questions