【发布时间】:2021-07-29 16:11:10
【问题描述】:
spek 尝试查找测试时我遇到了崩溃。我尝试了许多不同的版本和示例配置。我从命令行运行。 Gradle 4.0,mac osx。任何帮助将不胜感激!
这是错误:
WARNING: TestEngine with ID 'spek' failed to discover tests
java.lang.NoSuchMethodError: org.junit.platform.commons.util.ReflectionUtils.findAllClassesInClasspathRoot(Ljava/nio/file/Path;Ljava/util/function/Predicate;Ljava/util/function/Predicate;)Ljava/util/List;
at org.jetbrains.spek.engine.SpekTestEngine.resolveSpecs(SpekTestEngine.kt:66)
at org.jetbrains.spek.engine.SpekTestEngine.discover(SpekTestEngine.kt:50)
at org.junit.platform.launcher.core.DefaultLauncher.discoverEngineRoot(DefaultLauncher.java:130)
at org.junit.platform.launcher.core.DefaultLauncher.discoverRoot(DefaultLauncher.java:117)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
at org.junit.platform.launcher.Launcher.execute(Launcher.java:96)
at org.junit.platform.console.tasks.ConsoleTestExecutor.executeTests(ConsoleTestExecutor.java:65)
at org.junit.platform.console.tasks.ConsoleTestExecutor.lambda$execute$0(ConsoleTestExecutor.java:57)
at org.junit.platform.console.tasks.CustomContextClassLoaderExecutor.invoke(CustomContextClassLoaderExecutor.java:33)
at org.junit.platform.console.tasks.ConsoleTestExecutor.execute(ConsoleTestExecutor.java:57)
at org.junit.platform.console.ConsoleLauncher.executeTests(ConsoleLauncher.java:85)
at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:75)
at org.junit.platform.console.ConsoleLauncher.execute(ConsoleLauncher.java:48)
at org.junit.platform.console.ConsoleLauncher.main(ConsoleLauncher.java:40)
这是我当前的 build.gradle:
buildscript {
repositories {
jcenter()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M5'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$project.ext.kotlinVersion"
}
}
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'idea'
apply plugin: 'kotlin'
apply plugin: 'java'
junitPlatform {
filters {
engines {
include 'spek', 'junit-jupiter', 'junit-vintage'
}
}
}
dependencies {
compile("org.jetbrains.kotlin:kotlin-stdlib-jre8:$project.ext.kotlinVersion")
// testCompile 'junit:junit:4.12'
testCompile 'org.jetbrains.spek:spek-api:1.1.2'
testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2'
testCompile 'org.junit.platform:junit-platform-runner:1.0.0-M5'
testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0-M5'
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testRuntime "org.junit.vintage:junit-vintage-engine:4.12.0-M5"
testRuntime "org.junit.jupiter:junit-jupiter-engine:5.0.0-M5"
testRuntime "org.junit.platform:junit-platform-console:1.0.0-M5"
testCompile "com.google.code.gson:gson:$project.ext.gsonVersion"
}
repositories {
mavenCentral()
}
【问题讨论】:
-
在 Gradle 4.0 中,来自不同语言编译器的类被放置在不同的目录中:docs.gradle.org/current/release-notes.html 看起来,Spek 期望 Kotlin 类与早期版本一样位于 Java 输出目录中。所有使用类目录的工具都应更新以支持此功能。或者,尝试使用较早的 Gradle 版本。
-
尝试使用 junit 平台版本 1.0.0.M4(在 Spek 文档spekframework.org/docs/latest 中列出) - Junit 平台的新里程碑版本有时会引入破坏性 API 更改。
-
@JKLy 。你搞定了。只需要按照指示大声笑。将其发布为答案,我会接受。
标签: unit-testing kotlin spek