Setup
The Kotest test framework is supported on JVM, Javascript and Native. To enable Kotest for multiple platforms, combine the steps for the individual platforms as detailed in the following tabs.
The KMP support in Kotest 6.0 has changed from the previous versions. There is no longer a compiler plugi but a simplified setup. Please see the rest of this page for details on how to configure Kotest for KMP in Kotest 6.0 and later.
- JVM/Gradle
- Kotlin/JS
- Kotlin/WasmJS
- Kotlin/Native
- Android
A working project with JVM support can be found here: https://github.com/kotest/kotest-examples
Kotest on the JVM has two ways for running tests. One uses the Kotest gradle plugin, which provides detailed test output in the console, and a rich experience in Intellij (in conjuction with the Intellij Kotest plugin). The other option uses the JUnit Platform gradle plugin which is ubiquitous in the JVM ecosystem but lacks some features of the Kotest gradle plugin.
To use the Kotest gradle plugin, add the following to your build.gradle.kts
file:
plugins {
id("io.kotest") version "$version"
}
Add the following dependency to your build:
dependencies {
testImplementation("io.kotest:kotest-framework-engine:$version")
}
And then execute the kotest
task in gradle, or run tests directly from the IDE.
To use the JUnit Platform plugin, add the following to your build.gradle.kts
file:
tasks.withType<Test>().configureEach {
useJUnitPlatform()
}
Add the following dependency to your build:
dependencies {
testImplementation("io.kotest:kotest-runner-junit5:$version")
}
And then execute the test
task in gradle, or run tests directly from the IDE.
A working JS project can be found here: https://github.com/kotest/kotest-examples
Add the Kotest gradle plugin and Google KSP plugin to to your build.
For example:
plugins {
id("io.kotest") version "$version"
id("com.google.devtools.ksp") version "2.2.0-2.0.2"
}
Add the engine dependency to your commonTest
or jsTest
source set:
kotlin {
js()
sourceSets {
jsTest {
dependencies {
implementation("io.kotest:kotest-framework-engine:$version")
}
}
}
}
Tests can be placed in either commonTest
or jsTest
.
Run your tests using the jsKotest
gradle task.
The JS test engine is feature limited when compared to the JVM test engine. The major restriction is that annotation based configuration will not work as Kotlin does not expose annotations at runtime to JS code.
A working WasmJS project can be found here: https://github.com/kotest/kotest-examples
Add the Kotest gradle plugin and Google KSP plugin to to your build.
For example:
plugins {
id("io.kotest") version "$version"
id("com.google.devtools.ksp") version "2.2.0-2.0.2"
}
Add the engine dependency to your commonTest
or wasmJsTest
source set:
kotlin {
wasmJs()
sourceSets {
wasmJsTest {
dependencies {
implementation("io.kotest:kotest-framework-engine:$version")
}
}
}
}
Tests can be placed in either commonTest
or wasmJsTest
.
Run your tests using the wasmJsKotest
gradle task.
The WasmJS test engine is feature limited when compared to the JVM test engine. The major restriction is that annotation based configuration will not work as Kotlin does not expose annotations at runtime to Wasm code.
A working native project with linux, windows and macos configured, with unit and data driven test examples, can be found here: https://github.com/kotest/kotest-examples
Add the Kotest gradle plugin and Google KSP plugin to to your build.
For example:
plugins {
id("io.kotest") version "$version
id("com.google.devtools.ksp") version "2.2.0-2.0.2"
}
Add the engine dependency to your commonTest
, nativeTest
or platform specific sourceset:
kotlin {
linuxX64() // add any supported native target
sourceSets {
nativeTest {
dependencies {
implementation("io.kotest:kotest-framework-engine:$version")
}
}
}
}
Tests can be placed in either commonTest
or a specific native sourceset.
Run your tests using the kotest tasks that mirror the target names, for example linuxX86Kotest
.
The native test engine is feature limited when compared to the JVM test engine. The major restriction is that annotation based configuration will not work as Kotlin does not expose annotations at runtime to native code.
Currently, only Unit tests are supported in Kotest.
The following steps enable Kotest to be used for unit tests, where the Android framework is not needed or is mocked that usually reside in the
src/test
folder of your module.
Kotest on Android uses the JUnit Platform gradle plugin. This requires configuring the android test options block in your build file and then adding the Kotest junit5 runner dependency.
android.testOptions {
unitTests.all {
it.useJUnitPlatform()
}
}
dependencies {
testImplementation 'io.kotest:kotest-runner-junit5:version'
}
A working Android project with unit and data driven test examples, can be found here: https://github.com/kotest/kotest-examples
A working multiplatform project with JVM, JS and native targets, and unit and data driven test examples, can be found here: https://github.com/kotest/kotest-examples
To configure the test framework for multiplatform, combie the steps for JVM, JS and Native as detailed in the previous tabs.