gpt4 book ai didi

java - 无法在 IntelliJ 2017.3.3 中触发 "Migrate to JUnit 5"对话框

转载 作者:行者123 更新时间:2023-12-01 14:07:56 25 4
gpt4 key购买 nike

How the dialog should look

blog post说一旦 junit 5 在类路径上,你可以将鼠标悬停在 JUnit 4 测试名称上,并且会出现一个“迁移到 JUnit 5”的弹出窗口。我添加了 junit-jupiter-api依赖(版本 5.0.3 )到 pom 并且没有这样的选项可用。

我错过了什么?

最佳答案

我想这个功能现在默认是禁用的。也许这是与切换相关的错误。但是您可以手动启用此检查。

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

之后应用快速修复 迁移到 JUnit 5 然后按 启用检查 .

enter image description here

这种迁移对我有用。

enter image description here

开启后,您可以看到检查的工具提示:
enter image description here

对于此检查,您需要:

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

    这是来自 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);
    }

    关于java - 无法在 IntelliJ 2017.3.3 中触发 "Migrate to JUnit 5"对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48463230/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com