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's org.junit.* is not available there; kotlin.test is.
  • 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.assertEquals failures render as a plain AssertionError with 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 of kotlin.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.md and ../../../instrumentation/runner/running-instrumented-tests-with-androidjunit4/SKILL.md. (You can still use kotlin.test assertions inside those tests.)
  • The user is testing coroutines / FlowrunTest, TestScope, Dispatchers.setMain is ../../../jvm-tests/coroutines/testing-coroutines-with-runtest/SKILL.md; Turbine is ../../../jvm-tests/coroutines/testing-flows-with-turbine/SKILL.md. (kotlin.test supplies the assert* calls inside those.)
  • The user wants Compose UI assertions (assertIsDisplayed, assertTextEquals) — that is the compose/assertions/ skills, unrelated to kotlin.test.
Installs
36
GitHub Stars
319
First Seen
May 16, 2026
writing-tests-with-kotlin-test — skydoves/android-testing-skills