Draft:Kotest

Software Test Framework From Wikipedia, the free encyclopedia

Kotest is a test automation framework, assertions library and property testing library for the Kotlin programming language.[2] Kotest is used for unit testing, and is one of the xUnit frameworks. Kotest is one of the third party testing options recommended by Jetbrains in their Kotlin adoption guide[3].


DeveloperKotest framework organization
Stable release
6.1.5 / March 8, 2026; 8 days ago (2026-03-08)[1]
Written inKotlin
Quick facts Kotest, Developer ...
Kotest
DeveloperKotest framework organization
Stable release
6.1.5 / March 8, 2026; 8 days ago (2026-03-08)[1]
Written inKotlin
TypeTest framework
LicenseApache 2.0
Websitekotest.io
Repositorygithub.com/kotest/kotest
Close

Although Kotest is similar in function to many of the existing JVM based testing libraries, such as JUnit, it offers a Kotlin DSL that allows tests to be layered[4] and parameterized[5] in more powerful ways than standard class-method based testing libraries.

Kotest is available as a library from Maven central repository provided by Sonatype and is compatible with both Maven and Gradle build systems. The latest version of the framework, Kotest 6 resides under the Maven group name io.kotest.

In 2025, Apple began including Kotest[6] as a desired skill in their JVM based Wallet department job advertisements.

Kotest Styles

One of the defining features of Kotest is the ability to lay out tests in multiple ways to suit whatever preferences a development team may have. Kotest terms these styles as Specs. Examples include a Jasmine inspired layout named DescribeSpec, a BDD style layout named BehaviorSpec and a ScalaTest style layout called FunSpec.[7] There are eight spec styles in total.

Example of a Kotest spec

A Kotest test fixture, which is referred to as a Spec in Kotest, is a Kotlin class. Test cases are created as functions inside the class. If the situation requires it,[8] it is also possible to define lifecycle callbacks to execute functions before or after each (or all) of the test cases.

import io.kotest.core.spec.style.FunSpec

class MyTests : FunSpec({
    test("String length should return the length of the string") {
        "sammy".length shouldBe 5
        "".length shouldBe 0
    }
})

Assertions

The Kotest assertions library is one of the libraries that Jetbrains reference[9] as supporting Kotlin and Java. The following example shows some of the simplest Kotest's assertions:

2*2 shouldBe 4
3+1 shouldNotBe 5
"hello world" shouldStartWith "hello"

More advanced assertions explain the difference between expected and actual values in more detail. For instance, the following assertion does not find any exact match and fails, yet it finds a similar element:

listOf(sweetGreenApple, sweetGreenPear) shouldContain (sweetRedApple)

(snip)

PossibleMatches:
 expected: Fruit(name=apple, color=red, taste=sweet),
  but was: Fruit(name=apple, color=green, taste=sweet),
  The following fields did not match:
    "color" expected: <"red">, but was: <"green">

Assertions can be chained to allow fluent style, as follows:

val a: String? = "foo"

a.shouldNotBeNull()
    .shouldHaveLength(3)
    .shouldStartWith("fo")
    .shouldEndWith("oo")

Multiplatform Support

Kotlin Multiplatform is supported[10] by Kotest. Supported targets include JVM, Javascript, WasmJS, WasmWasi, Macos, Linux, Windows, Android, Android-Native, iOS, tvOS and WatchOS.[11]

Integrations

Kotest integrates with many of the standard JVM testing libraries, as well as more specific Kotlin testing extensions. Such integrations include the cross platform Docker based TestContainers project, the Kotlin focused mocking library MockK, and Spring Test Profiles support.

Additionally, an Intellij IDEA plugin is provided to execute tests directly from any Intellij based IDE.[12]

Community

An official #kotest channel is available in the KotlinLang Slack workspace, which can be joined via the Kotlin community page.[13]

Technology Radar

Kotest has featured in multiple editions of the bi‑annual Thoughtworks Technology Radar. It first appeared in Volume 21 (November 2019) in the Assess ring, was promoted to the Trial ring in Volume 26 (March 2022), and reached the Adopt ring in Volume 27 (October 2022). The Radar highlights Kotest’s variety of testing styles, extensive matcher library, support for property‑based testing and its IntelliJ IDEA plug‑in as key reasons for adoption.[14]

See also

  • JUnit, unit testing framework for the Java programming language
  • Mockito, mocking extensions to JUnit
  • TestNG, test framework for Java
  • Spock, test framework for Groovy
  • Jasmine, test framework for Javascript

References

Related Articles

Wikiwand AI