/kotest-skills:kotestfrom kotest-skills
Write, review, migrate, and debug Kotlin tests with Kotest 6.x: spec styles, matchers, data-driven tests, property-based testing, lifecycle hooks, extensions, and Kotlin Multiplatform setup.
Ships in kotest-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
This skill covers Kotest 6.2. Kotest has three parts that can be used independently: the test framework, the assertions library (which works under any framework, including JUnit), and property testing.
build.gradle.kts or gradle/libs.versions.toml.
kotlin("multiplatform"), commonTest).io.kotest or com.sksamuel.kotest in old code),
indentation, and helpers. Don't introduce a second spec style into a module.ProjectConfig / PackageConfig and any registered extensions.With Bash available, scripts/analyze-project.sh [dir] prints a summary of all of this.
| Task | Read |
|---|---|
| New project / add Kotest to a build | SETUP-REFERENCE.md |
| Write tests in a style | SPEC-STYLES.md |
| Choose a matcher, custom matchers, soft assertions | ASSERTIONS-REFERENCE.md |
| Data-driven tests, config, coroutines, tags, extensions | FRAMEWORK-REFERENCE.md |
| Property-based testing | PROPERTY-TESTING-REFERENCE.md |
| Migrate from JUnit / TestNG / Spek | MIGRATION-GUIDE.md |
| Tests not running, config ignored, hangs | KOTEST-DEBUGGING.md, KNOWN-ISSUES.md |
Load only the reference you need.
// JVM — build.gradle.kts
dependencies {
testImplementation("io.kotest:kotest-runner-junit5:<version>")
testImplementation("io.kotest:kotest-assertions-core:<version>")
testImplementation("io.kotest:kotest-property:<version>") // if needed
}
tasks.withType<Test>().configureEach { useJUnitPlatform() }
For KMP, apply id("com.google.devtools.ksp") and id("io.kotest"), then put kotest-framework-engine and
kotest-assertions-core in commonTest. Add kotest-runner-junit5 and useJUnitPlatform() for the JVM target.
See SETUP-REFERENCE for JS, Wasm, Native, and Android.
import io.kotest.assertions.assertSoftly
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
import io.kotest.datatest.withTests
import io.kotest.matchers.collections.shouldContainExactly
import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldContain
import io.kotest.matchers.types.shouldBeInstanceOf
class OrderServiceTest : FunSpec({
val repo = InMemoryOrderRepo()
val service = OrderService(repo)
beforeEach { repo.clear() }
context("placing an order") {
test("stores the order with its lines") {
val order = service.place(cart("apple", "pear"))
assertSoftly(repo.find(order.id)) {
status shouldBe Status.PLACED
lines.map { it.sku } shouldContainExactly listOf("apple", "pear")
}
}
test("rejects an empty cart") {
val e = shouldThrow<IllegalArgumentException> { service.place(cart()) }
e.message shouldContain "empty"
}
withTests(-1, 0) { qty ->
shouldThrow<IllegalArgumentException> { service.place(cart("apple" to qty)) }
}
}
test("returns a typed result") {
val result = service.lookup("A-1").shouldBeInstanceOf<Found>() // smart-casts and returns Found
withClue("lookup A-1") { result.order.id shouldBe "A-1" }
}
})
Rules:
list.shouldContain(x), str.shouldStartWith("a"), n shouldBeGreaterThan 0
rather than (cond) shouldBe true, so the failure message carries the actual values.shouldThrow, shouldNotBeNull, shouldBeInstanceOf,
shouldBeSingle, and shouldBeSuccess return their subject, so you don't need !! or casts.suspend. Never wrap them in runBlocking. For delays, use coroutineTestScope = true and
virtual time.eventually, not Thread.sleep. Write eventually(5.seconds) { ... } to poll for an asynchronous
result, and continually to assert that something stays true.assertSoftly so one run reports every failure. Use withClue or asClue to add context.withTests for leaf
tests and withContexts for groups. Each style has its own variant; see FRAMEWORK-REFERENCE.checkAll(Arb.int(), Arb.int()) { a, b -> (a + b) shouldBe (b + a) }.beforeEach or use
isolationMode = IsolationMode.InstancePerRoot."rejects an empty cart", not "test1". Names must be unique within a scope.| Wrong (5.x / hallucinated) | Correct (6.2) |
|---|---|
kotest-framework-datatest dependency | Built into the engine; import io.kotest.datatest.* |
withData as the only data-test function | withTests / withContexts / per-style variants (withIts, withShoulds, …) |
specConcurrencyMode, testConcurrencyMode, parallelism | specExecutionMode = SpecExecutionMode.Concurrent, testExecutionMode (JVM only) |
./gradlew test -Dkotest.tags=... | KOTEST_TAGS="A & !B" ./gradlew test, or systemProperty(...) on the Test task |
@AutoScan extensions | Removed; register via extension(...) or ProjectConfig.extensions |
IsolationMode.InstancePerTest / InstancePerLeaf | IsolationMode.InstancePerRoot |
TestContainerExtension(...) / ContainerExtension(...) | install(TestContainerSpecExtension(container)) (old ones removed in 6.3) |
forAll(row(...)) table tests from core | kotest-assertions-table (io.kotest.data), or prefer data-driven tests |
import io.kotest.assertions.nondeterministic.retry | import io.kotest.assertions.retry; retry(maxRetry, timeout, delay) |
object ProjectConfig everywhere | class ProjectConfig : AbstractProjectConfig() (Native requires a class) |
kotest-assertions-api | kotest-assertions-shared |
Constructor-injected Spring spec using extension(SpringExtension()) | @ApplyExtension(SpringExtension::class) on the class |
a shouldEqual b (io.kotest.matchers.equals): a type-safe shouldBe, so 1 shouldEqual "1" doesn't compile.actual withEqs { register<BigDecimal>(myEq) } shouldBe expected (io.kotest.assertions.eq), where myEq is
your own Eq<BigDecimal>: per-assertion equality overrides that apply recursively into collections and data
classes, and are safe under concurrency (unlike the global DefaultEqResolver.register).shouldBeEqualUsingFields { excludedProperties = setOf(Foo::updatedAt); expected } (JVM): field-by-field diffs.shouldEqualJson { overrideMatchers = mapOf("users" to matchArraysContainingAll()); expected }: custom matchers for
JSON subtrees, keyed by dotted paths like "users.[0].name" — e.g. partial array matching with
matchArraysContainingAll() (see ASSERTIONS-REFERENCE).list.shouldBeSingle() returns the element; result.shouldBeFailure<IOException> { }; x.shouldBeInstanceOf(Foo::class) returns Foo.DefaultTestConfig, PackageConfig, and failfast give layered configuration.coroutineTestScope = true with testCoroutineScheduler gives virtual time. On Kotest ≤ 6.2.6 also add
kotlinx-coroutines-test to test deps to call scheduler methods.kotest-property-permutations, experimental) is a property-testing alternative.kotest { } block: kotestVersion (aligns artifact versions), enablePowerAssert, and alwaysRerunTests.AbstractSpec + @TestRunnable../gradlew test # JVM
./gradlew test --tests "com.example.OrderServiceTest" # one spec
./gradlew allTests # KMP: every target (or jvmTest, jsTest, linuxX64Test, ...)
KOTEST_DEBUG=true ./gradlew test --info # engine debug output (see KOTEST-DEBUGGING)
After writing or migrating tests, run them and confirm they were discovered: the report shows a non-zero
count, and "0 tests" usually means a missing useJUnitPlatform() or KSP plugin. If tests pass on the first
run, deliberately break one assertion to check that it can fail. For full setup or migration work, go
through assets/checklist.md.
assets/checklist.md (opens in a new tab)references/ASSERTIONS-REFERENCE.md (opens in a new tab)references/FRAMEWORK-REFERENCE.md (opens in a new tab)references/KNOWN-ISSUES.md (opens in a new tab)references/KOTEST-DEBUGGING.md (opens in a new tab)references/MIGRATION-GUIDE.md (opens in a new tab)references/PROPERTY-TESTING-REFERENCE.md (opens in a new tab)references/SETUP-REFERENCE.md (opens in a new tab)references/SPEC-STYLES.md (opens in a new tab)scripts/analyze-project.sh (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub kotest/kotest --plugin kotest-skillsOther plugins' skills for the same job