从 Intellij 启动时,kotlintest 测试运行得非常好,但是当我尝试使用 gradle test task 命令运行它们时,只能找到并运行我的常规 JUnit 测试。
kotlintest 代码:
import io.kotlintest.matchers.shouldBe
import io.kotlintest.specs.StringSpec
class HelloKotlinTest : StringSpec() {
init {
println("Start Kotlin UnitTest")
"length should return size of string" {
"hello".length shouldBe 5
}
}
}
构建.gradle:
apply plugin: 'org.junit.platform.gradle.plugin'
buildscript {
ext.kotlinVersion = '1.1.3'
ext.junitPlatformVersion = '1.0.0-M4'
repositories {
maven { url 'http://nexus.acompany.ch/content/groups/public' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.junit.platform:junit-platform-gradle-plugin:$junitPlatformVersion"
}
}
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
test.kotlin.srcDirs += 'test/main/kotlin'
}
(...)
dependencies {
// Kotlin
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jre8', version: kotlinVersion
// Kotlin Test
testCompile group: 'io.kotlintest', name: 'kotlintest', version: kotlinTestVersion
// JUnit 5
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion
testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitJupiterVersion
}