简体   繁体   English

迁移后 IntelliJ 无法加载 JUnit5

[英]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).我正在试验我认为纯粹与Intellij相关的问题(尽管我不知道如何解决它,也不知道它来自哪里)。 I basically followed this tutorial to migrate tests from JUnit 4 to 5.我基本上按照本教程将测试从 JUnit 4 迁移到 5。

Tests after migration迁移后的测试

By the end of the migration, I now have the following dependencies in pom.xml在迁移结束时,我现在在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.在 IntelliJ 中运行测试时,我不断收到Cannot resolve symbol 'jupiter' However, everything is OK in my CI pipeline ???.. (so probably something wrong in IntelliJ).但是,在我的 CI 管道中一切正常???..(所以 IntelliJ 中可能有问题)。 No matter the fix actions proposed (resp. Add JUnit 5.4 to classpath and Add Maven dependencies ), I keep getting the same.无论建议的修复操作(分别Add JUnit 5.4 to classpathAdd Maven dependencies ),我一直得到相同的结果。 So what's next?下一个是什么?

在此处输入图像描述

Environment环境

  • openjdk11打开jdk11
  • IntelliJ 2020.3.1 IntelliJ 2020.3.1

Interestingly, changes do not seem to be reflected on cockpit.iml , for it still contains有趣的是,变化似乎并没有反映在cockpit.iml上,因为它仍然包含

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

and no mention of JUnit 5. Are both problems related?并且没有提到 JUnit 5. 这两个问题是否相关?

What I tried我试过的

  • based on this documentation , I added org.junit.platform : junit-platform-launcher基于此文档,我添加了org.junit.platformjunit-platform-launcher
  • I tried File | Invalidate Caches我试过File | Invalidate Caches File | Invalidate Caches sources File | Invalidate Caches无效
  • remove .idea and cockpit.iml to reimport everything.删除.ideacockpit.iml以重新导入所有内容。

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.我将 Junit 添加到 Maven pom 文件并修复它。

https://mvnrepository.com/artifact/junit/junit/4.13.1 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).事实证明: pom.xml某处的语法错误阻止了IntelliJ正确下载新的依赖项(或者看起来如此)。 The refresh maven deps button disappeared after clicking but libraries were not downloaded.刷新 maven deps按钮点击后消失但库没有下载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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