Skip to main content
Version: 6.2 🚧

Setup

The Kotest test framework is supported on all targets, including JVM, JavaScript, Native and Wasm. To enable Kotest for multiple platforms, follow the steps for the platform you are targeting as detailed in the following tabs.

Migrating to Kotest 6

The Kotlin multiplatform setup in Kotest 6.0 has changed from previous versions. The Kotest Gradle plugin has been renamed to io.kotest. Also, the compiler plugin has been replaced with a more robust method using KSP. Please see the rest of this page for details on how to configure Kotest for KMP in Kotest 6.0 and later.

tip

When running the Gradle test task, Gradle will cache the output and report no tests executed if no source code has changed. See the section on rerunning tests for details on how to disable this behaviour.

Install the IntelliJ Plugin

Kotest provides an IntelliJ plugin for enhanced UX, including the ability to run individual tests, tool windows to show test layouts, and jump to source.

Example Project

A working project with JVM support can be found here: https://github.com/kotest/kotest-examples

Kotest on the JVM builds atop of the JUnit Platform project which is widely supported in the JVM ecosystem.

To use the JUnit Platform support, first configure Gradle to use JUnit platform support:

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

Andd then add the following dependency to your build:

dependencies {
testImplementation("io.kotest:kotest-runner-junit5:<kotest-version>")
}

And then execute the test task in gradle, or run tests directly from the IDE.

Enhanced IDE support​

For enhanced support for jump-to-source and re-running failed tests from the test results tree, in addition to installing the Kotest Intellij Plugin into your IDE, add the Kotest Gradle plugin to your build.

For example:

plugins {
id("io.kotest").version("<kotest-version>")
}

Then you can jump-to-source for tests at any level:

jump to source

As well as re-run all failed tests:

re-run failed

Or re-run a single test from the results tree:

re-run selected

Re-running tests​

By default, Gradle's incremental build will skip running tests if no source code has changed, marking the task as UP-TO-DATE. This can be inconvenient during debugging.

To force your tests to run every time, you can temporarily add the following configuration to your build.gradle.kts file:

tasks.withType<Test>().configureEach {
logger.lifecycle("UP-TO-DATE check for $name is disabled, forcing it to run.")
outputs.upToDateWhen { false }
}

Alternatively, if you have the Kotest Gradle Plugin installed, you can ask Kotest to do this for you:

kotest {
alwaysRerunTests = true
}

Quick Alternative: For a single re-run without modifying build files, you can use the --rerun flag from the command line:

./gradlew test --rerun