我正在为我的Kotlin项目使用Spek Testing框架。我能够通过Intellij Idea Spek插件进行测试,但无法通过Gradle(构建或测试)运行它们。根据SimpleTest.kt,当从Idea插件1测试中运行时,通过Gradle运行时1个失败,它说1个具有0个测试的容器。如何通过Gradle设置测试的发布?
我的gradle和测试文件:
build.gradle:
buildscript {
ext.kotlin_version = '1.1.4-2'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4"
}
}
apply plugin: "idea"
apply plugin: "java"
apply plugin: "kotlin"
apply plugin: "application"
apply plugin: "org.junit.platform.gradle.plugin"
junitPlatform {
filters {
engines {
include 'spek'
}
}
}
mainClassName = "app.MainKt"
repositories {
mavenCentral()
jcenter()
maven { url "http://dl.bintray.com/jetbrains/spek" }
}
dependencies {
testCompile 'org.jetbrains.kotlin:kotlin-test'
testCompile 'org.jetbrains.spek:spek-api:1.1.2'
testCompile 'org.junit.platform:junit-platform-runner:1.0.0-M4'
testRuntime 'org.jetbrains.spek:spek-junit-platform-engine:1.1.2'
}
sourceSets.test.java.srcDirs += 'src/test/kotlin'
src/test/kotlin/simpletest.kt:
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import kotlin.test.assertEquals
class SimpleTest : Spek({
given("simple test") {
it("should succeed") {
assertEquals(1, 1)
}
it("shouldn't succeed") {
assertEquals(0, 1)
}
}
})
Gradle测试输出:
Executing external task 'test'...
Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0
:generateBuildConfig UP-TO-DATE
:compileBuildConfig UP-TO-DATE
:extractIncludeProto UP-TO-DATE
:extractProto UP-TO-DATE
:generateProto UP-TO-DATE
:compileKotlin UP-TO-DATE
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:compileTestKotlin
Using kotlin incremental compilation
:extractIncludeTestProto UP-TO-DATE
:extractTestProto UP-TO-DATE
:generateTestProto NO-SOURCE
:compileTestJava NO-SOURCE
:processTestResources NO-SOURCE
:testClasses UP-TO-DATE
:junitPlatformTest
Test run finished after 5062 ms
[ 1 containers found ]
[ 0 containers skipped ]
[ 1 containers started ]
[ 0 containers aborted ]
[ 1 containers successful ]
[ 0 containers failed ]
[ 0 tests found ]
[ 0 tests skipped ]
[ 0 tests started ]
[ 0 tests aborted ]
[ 0 tests successful ]
[ 0 tests failed ]
:test
:test SKIPPED
BUILD SUCCESSFUL in 14s
12 actionable tasks: 2 executed, 10 up-to-date
External task execution finished 'test'.
这是由于这个问题造成了SPEK 1.1.2和Kotlin 1.1.4 https://github.com/jetbrains/jetbrains/spek/issues/248
可以通过使用SPEK 1.1.4和JUNIT-PLATFORM 1.0.0-RC2