Kotest
| Developer(s) | Kotest framework organization |
|---|---|
| Stable release | 6.0.02
/ June 6, 2024[1] |
| Repository | github |
| Written in | Kotlin |
| Engine | |
| Type | Test framework |
| License | Apache 2.0 |
| Website | kotest |
Search Kotest on Amazon.
Kotest is a test automation framework for the Kotlin programming language.[2] Kotest is used for unit testing, and is one of the xUnit frameworks.
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[3] and parameterized[4] in more powerful ways than standard class-method based testing libraries.
Kotest is linked as a JAR at compile-time. The latest version of the framework, Kotest 6 resides under the Maven group name io.kotest.
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 Javascript inspired layout named DescribeSpec, a BDD style layout named BehaviorSpec and a ScalaTest style layout called FunSpec.[5] There are ten 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,[6] 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 following example shows some of the simplest Kotest's assertions:
2*2 shouldBe 4
2*2 shouldNotBe 5
2*2 shouldNotBe "4"
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 by Kotest. Supported targets include JVM, Javascript, WasmJS, WasmWasi, Macos, Linux, Windows, Android, Android-Native, iOS, tvOS and WatchOS.[7]
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.[8]
Community
An official #kotest channel is available in the KotlinLang Slack workspace, which can be joined via the Kotlin community page.[9]
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.[10]
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
References
- ↑ "Release Notes". Sonatype Central. Retrieved 6 September 2025.
- ↑ Learn Kotlin Programming. Packt. ISBN 9781789808742. Retrieved 6 September 2025. Search this book on
- ↑ "Kotest: The Kotlin Testing Framework You'll Love". SoftwareMill. Retrieved 6 September 2025.
- ↑ "JUnit 5 vs Kotest. Part 2: Parameterise 'Em All". 20 August 2023. Retrieved 6 September 2025.
- ↑ "Introduction to Kotest". Baeldung. 5 February 2022. Retrieved 6 September 2025.
- ↑ Kent Beck. "Expensive Setup Smell". C2 Wiki. Retrieved 2025-07-29.
- ↑ "Test your multiplatform app − tutorial | Kotlin Multiplatform". Kotlin Multiplatform Help. Retrieved 6 September 2025.
- ↑ "kotest - IntelliJ IDEs Plugin | Marketplace". JetBrains Marketplace. Retrieved 6 September 2025.
- ↑ "Kotlin Community Slack". kotlinlang.org. Retrieved 29 July 2025.
- ↑ "Kotest - Technology Radar entry". Thoughtworks Technology Radar. Thoughtworks. 26 October 2022. Retrieved 29 July 2025.
External links
This article "Kotest" is from Wikipedia. The list of its authors can be seen in its historical and/or the page Edithistory:Kotest. Articles copied from Draft Namespace on Wikipedia could be seen on the Draft Namespace of Wikipedia and not main one.
