简体   繁体   中英

IntelliJ fails to load JUnit5 after migration

I am experimenting what I think to be a purely Intellij related issue (though I don't know how to fix it nor where it comes from). I basically followed this tutorial to migrate tests from JUnit 4 to 5.

Tests after migration

By the end of the migration, I now have the following dependencies in pom.xml

   <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.6.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>5.6.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
      <version>5.6.3</version>
      <scope>test</scope>
    </dependency>

and the different Test Classes now uses

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

Problem

I keep getting Cannot resolve symbol 'jupiter' while running tests in IntelliJ. However, everything is OK in my CI pipeline ???.. (so probably something wrong in IntelliJ). No matter the fix actions proposed (resp. Add JUnit 5.4 to classpath and Add Maven dependencies ), I keep getting the same. So what's next?

在此处输入图像描述

Environment

  • openjdk11
  • IntelliJ 2020.3.1

Interestingly, changes do not seem to be reflected on cockpit.iml , for it still contains

 <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />

and no mention of JUnit 5. Are both problems related?

What I tried

  • based on this documentation , I added org.junit.platform : junit-platform-launcher
  • I tried File | Invalidate Caches File | Invalidate Caches sources
  • remove .idea and cockpit.iml to reimport everything.

There is a mismatch somewhere but I can't figure where

exactly same issue. I added the Junit to Maven pom file and it fixed it.

https://mvnrepository.com/artifact/junit/junit/4.13.1

Turns out: a syntax error somewhere in pom.xml prevented IntelliJ from properly downloading new dependencies (or so it seems). The refresh maven deps button disappeared after clicking but libraries were not downloaded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM