无法在IntelliJ 2017.3.3中触发“迁移到JUnit 5”对话框

edw*_*yte 2 java intellij-idea maven junit5

对话框的外观

这篇博客文章说,一旦将junit 5放在类路径上,就可以将鼠标悬停在JUnit 4测试名称上,并且将出现“迁移到JUnit 5”的弹出窗口。我已经将junit-jupiter-api依赖项(version 5.0.3)添加到pom中,并且没有这样的选项可用。

我想念什么?

Eug*_*ene 6

我猜现在默认情况下禁用此功能。也许是与切换有关的错误。但是您可以手动启用此检查。

尝试右键单击测试名称->分析|按名称运行检查-> JUnit 4测试可以是JUnit 5检查

之后,将快速修复程序“ 迁移到JUnit 5”并按“ 启用检查”

在此处输入图片说明

此迁移对我有用。

在此处输入图片说明

开启后,您可以看到检查的工具提示: 在此处输入图片说明

对于此检查,您需要:

  • JDK8;
  • 您的类路径中的“ org.junit.jupiter.api.Assertions”类;

您需要添加依赖项junit-jupiter-api:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>${junit-jupiter-engine.version}</version>
    <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

这是来自Idea来源的信息:

@Override
  public boolean shouldInspect(PsiFile file) {
    if (!JavaVersionService.getInstance().isAtLeast(file, JavaSdkVersion.JDK_1_8)) return false;
    if (JavaPsiFacade.getInstance(file.getProject()).findClass(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, file.getResolveScope()) == null) {
      return false;
    }
    return super.shouldInspect(file);
  }
Run Code Online (Sandbox Code Playgroud)