JUnit5和IntelliJ IDEA:使用反引号和括号的Kotlin函数命名

问题描述

JUnit 4 升级到 JUnit 5 并从org.junit.Test升级到org.junit.jupiter.api.Test后,如果您通过直接运行测试方法,则测试调用将停止工作 IntelliJ IDEA (按类运行测试效果很好),用于在Kotlin中使用方括号和反引号进行测试。

解决方法是从测试名称中删除括号。请参见下面的Kotlin示例。

JUnit 4:

import org.junit.Test

class A {
    @Test
    fun `my (fun)` (){
    }
}

当您直接从Idea中运行此方法时,效果很好

JUnit 5:

import org.junit.jupiter.api.Test

class A {
    @Test
    fun `my (fun)` (){
    }
}

由于名称中带有花括号“()”而异常失败:

org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
    at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:189)
    at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:168)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:132)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: org.junit.platform.commons.JUnitException: MethodSelector [className = 'dsf.A',methodName = 'my ',methodParameterTypes = 'fun'] resolution failed

我知道发生问题是因为JUnit中的API发生了变化,现在IntelliJ传递了带有括号的参数,这些括号已被解析为一些新的JUnitApi参数。

但是有人可以帮助您理解此问题的深层根源。是Idea中的功能性错误还是JUnit中的错误?

PS越野车奖金:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...