0Pricing
Kotlin Multiplatform Academy · Lesson

Where Tests Live: commonTest & Friends

Source sets for shared and platform-specific tests.

Where Tests Live: commonTest & Friends is a free Kotlin Multiplatform Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Kotlin Multiplatform Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Tests Get Source Sets Too

Just like your main code, tests live in their own source sets, mirroring commonMain, androidMain and iosMain.

Meet commonTest

commonTest holds tests that run on every platform. Write a test once and verify your shared logic everywhere. ✅

The kotlin.test Library

Common tests use the multiplatform kotlin.test library, which gives you assertions that work on all targets.

commonTest.dependencies {
    implementation(kotlin("test"))
}

A First Shared Test

A common test reads like any unit test, using a portable assertEquals to check shared behavior.

@Test
fun greetsName() {
    assertEquals("Hi, Sam", greet("Sam"))
}

androidUnitTest

Need a JVM-only test? Put it in androidUnitTest, where you can use JUnit and Android-specific helpers.

iosTest

iOS-specific tests live in iosTest. They run on the simulator using Kotlin/Native's test runner.

Common Tests Run On All

A test in commonTest executes on both the Android and iOS test tasks, catching platform differences early.

Run the Android Suite

From the terminal, a single Gradle task runs the JVM-side tests, including the common ones.

./gradlew :shared:testDebugUnitTest

Run the iOS Suite

Another task runs the same shared tests on the iOS simulator target, confirming parity.

./gradlew :shared:iosSimulatorArm64Test

Why Test in Common

Testing shared logic in commonTest means one suite guards both apps, so a fix is proven on every platform at once.

Keep Tests Where Code Is

Mirror your main sets: common logic gets common tests, platform code gets platform tests. The structure stays predictable.

Quick Check

Pick the right test home.

Recap

Tests mirror the source sets: commonTest for shared, androidUnitTest and iosTest for platform-specific checks.

Frequently asked questions

Is the “Where Tests Live: commonTest & Friends” lesson free?

Yes — the full text of “Where Tests Live: commonTest & Friends” is free to read here on the web, and the Kotlin Multiplatform Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Kotlin Multiplatform Academy course, upgrade to CoddyKit PRO.

What will I learn in “Where Tests Live: commonTest & Friends”?

Source sets for shared and platform-specific tests. You practise Kotlin Multiplatform Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Kotlin Multiplatform Academy?

No prior experience is required. Kotlin Multiplatform Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Where Tests Live: commonTest & Friends” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Kotlin Multiplatform Academy lesson?

Yes. Every Kotlin Multiplatform Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The shared Module vs the App Modules
  2. commonMain, androidMain & iosMain
  3. Reading the shared build.gradle.kts
  4. Where Tests Live: commonTest & Friends
← Back to Kotlin Multiplatform Academy