gpt4 book ai didi

android - java.lang.ClassNotFoundException : com. intellij.junit5.JUnit5IdeaTestRunner 在 kotlin 中使用 spek

转载 作者:IT老高 更新时间:2023-10-28 13:39:57 32 4
gpt4 key购买 nike

我是在 kotlin 测试中使用 spek 的新手。使用 spek 时,在 logcat 上出现以下错误。我不明白我为什么得到这个

java.lang.ClassNotFoundException: com.intellij.junit5.JUnit5IdeaTestRunner
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.junit.JUnitStarter.getAgentClass(JUnitStarter.java:252)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

我对 gradle 文件有以下依赖关系

testImplementation 'junit:junit:4.12'
testImplementation 'org.jetbrains.spek:spek-api:1.1.0-beta3'
testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.0-beta3'
testImplementation 'org.junit.platform:junit-platform-runner:1.0.0-M3'

测试文件

import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.junit.Assert.assertEquals
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.RunWith

@RunWith(JUnitPlatform::class)
class ExampleUnitTest : Spek({
val x = 2
val y = 3

given("x = $x and y = $y") {
val sum = x + y

it("should be that x + y = 5") {
assertEquals(5, sum)
}

it("should be that x - y = -1") {
val subtract = x - y
assertEquals(-1, subtract)
}

}
})

你能否建议,如何得到这种错误。我会感谢您对此主题的宝贵建议或意见。

最佳答案

您只需添加包含运行者的库(另见 http://junit.org/junit5/docs/current/user-guide/#installation)

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0-M3'

我鼓励您也将您的 spek-libs 更新到最新版本:

testImplementation 'junit:junit:4.12'
testImplementation 'org.jetbrains.spek:spek-api:1.1.2'
testImplementation 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2'
testImplementation 'org.junit.platform:junit-platform-runner:1.0.0-M5'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0-M5'

更新

目前最新的junit lib不兼容whte M5-Milestone,所以使用M4版本

testImplementation 'org.junit.platform:junit-platform-runner:1.0.0-M4'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.0.0-M4'

关于android - java.lang.ClassNotFoundException : com. intellij.junit5.JUnit5IdeaTestRunner 在 kotlin 中使用 spek,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44919436/

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