How can I run kotlintest tests with gradle?

感情迁移 提交于 2019-12-05 06:34:24

In KotlinTest 3.1.x you don't need to use Junit4 anymore. It is fully compatible with JUnit 5. Thus the answer to your question is to upgrade to the 3.1.x track.

You need to add useJUnitPlatform() to the test block in your build.gradle.

You need to add testCompile 'io.kotlintest:kotlintest-runner-junit5:3.1.9' to your dependencies.

For example.

dependencies {
    testCompile 'io.kotlintest:kotlintest-runner-junit5:3.1.9'
}

test {
    useJUnitPlatform()

    // show standard out and standard error of the test JVM(s) on the console
    testLogging.showStandardStreams = true

    testLogging {
        events "PASSED", "FAILED", "SKIPPED", "STANDARD_OUT", "STANDARD_ERROR"
    }
}

The "solution" was to switch back to JUnit 4.

kotlintest was not build with JUnit 5 in mind and does not provide its own junit-engine.

(Note: It should be possible to tell JUnit 5 to use the JUnit 4 engine for kotlintest. If anybody knows how to do this, please add the solution here.)

In order to run your kotlintest tests with Junit5 you need to use the KTestRunner.

@RunWith(KTestJUnitRunner::class)
class MyTest : FunSpec({
    test("A test") {
        1 + 1 shouldBe 2
    }
})

With the following gradle config for example.

dependencies {
    testCompile("io.kotlintest:kotlintest:${kotlinTestVersion}")
    testCompile("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!