writing-tests-with-kotlin-test
Installation
SKILL.md
Writing Tests With kotlin.test — One Assertion API Across Every Target
kotlin.test is Kotlin's own thin test library: framework-agnostic assert* functions plus @Test/@BeforeTest/@AfterTest annotations that typealias onto whatever runner is on the classpath (JUnit4, JUnit5, TestNG, the JS/Native runners). Write import kotlin.test.* once and the same test source compiles in commonTest, on the JVM, and on every Kotlin Multiplatform target. This skill covers the API surface, the @OnlyInputTypes compile-time guard, the Asserter extension point, and the Gradle wiring. It is the assertion layer; the runner layer for Android instrumentation is ../../../jvm-tests/runner/configuring-junit4-on-android/SKILL.md.
When to use this skill
- The module is Kotlin Multiplatform and tests live in
commonTest— JUnit'sorg.junit.*is not available there;kotlin.testis. - The user wants one assertion vocabulary that reads the same on JVM, Android, JS, and Native.
- The user reaches for
assertFailsWith<IllegalStateException> { … },assertContentEquals(...),assertIs<Foo>(value),assertContains(list, x),expect(3) { compute() }, or@BeforeTest/@AfterTest. - A JVM module has
testImplementation(kotlin("test"))and the test "runs on JUnit but I never added JUnit" — explaining the capability-based resolution. kotlin.test.assertEqualsfailures render as a plainAssertionErrorwith no diff, and the user wants the JUnit-style comparison failure back.
When NOT to use this skill
- The user wants rich fluent assertions (
assertThat(x).isEqualTo(...), soft assertions, collection matchers) — that is AssertJ / Google Truth / Kotest assertions, deliberately out ofkotlin.test's minimal scope. - The user is writing an Android instrumentation test and asking about the runner (
@RunWith(AndroidJUnit4::class),AndroidJUnitRunner,androidx.test:*) — use../../../jvm-tests/runner/configuring-junit4-on-android/SKILL.mdand../../../instrumentation/runner/running-instrumented-tests-with-androidjunit4/SKILL.md. (You can still usekotlin.testassertions inside those tests.) - The user is testing coroutines /
Flow—runTest,TestScope,Dispatchers.setMainis../../../jvm-tests/coroutines/testing-coroutines-with-runtest/SKILL.md; Turbine is../../../jvm-tests/coroutines/testing-flows-with-turbine/SKILL.md. (kotlin.testsupplies theassert*calls inside those.) - The user wants Compose UI assertions (
assertIsDisplayed,assertTextEquals) — that is thecompose/assertions/skills, unrelated tokotlin.test.