我怎样才能用gradle运行kotlintest测试?
从Intellij开始,kotlintest测试运行得非常好,但是当我尝试用gradle测试任务命令运行它们时,只发现并运行了常规的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 } } }
的build.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 }
“解决方案”是切换回JUnit 4。
kotlintest不是用JUnit 5构建的,也不提供它自己的junit-engine。
(注意:应该可以告诉JUnit 5使用JUnit 4引擎进行kotlintest,如果有人知道如何做,请在这里添加解决方案。)
- Android Gradle奇怪的错误
- Kotlin文件不能使用R.java
- java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并dex
- java.lang.NoClassDefFoundError:kotlin / jvm / internal / intrinsics in libgdx
- 如何用gradle kotlin脚本创建fat jar
- 具有不同源代码集的Gradle任务
- 在多项目设置中ConfigurationsContainer为空
- kotlin-gradle插件自动配置错误
- Java完成非零退出值2 – Android Gradle