此 blog post说一旦 junit 5 在类路径上,你可以将鼠标悬停在 JUnit 4 测试名称上,并且会出现一个“迁移到 JUnit 5”的弹出窗口。我添加了 junit-jupiter-api
依赖(版本 5.0.3
)到 pom 并且没有这样的选项可用。
我错过了什么?
最佳答案
我想这个功能现在默认是禁用的。也许这是与切换相关的错误。但是您可以手动启用此检查。
尝试右键单击测试名称 -> 分析|按名称运行检查 -> JUnit 4 测试可以进行 JUnit 5 检查
之后应用快速修复 迁移到 JUnit 5 然后按 启用检查 .
这种迁移对我有用。
开启后,您可以看到检查的工具提示:
对于此检查,您需要:
需要添加依赖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/