Kotlin Multiplatform Academy · レッスン

テストはどこにあるか:commonTestと仲間たち

共有テストとプラットフォーム固有テスト用のソースセットを学びます

レッスン 4/413 ステップ

「テストはどこにあるか:commonTestと仲間たち」はCoddyKit上の無料Kotlin Multiplatform Academyレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはKotlin Multiplatform Academy学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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.

無料で開始

AI チューターと学ぶ Kotlin — 無料

ブラウザでリアルコードを書いて実行し、24/7 の AI チューターから瞬時にサポートを受け、ウェブまたはアプリで続きから学習できます。

コース
30
レッスン
120

よくある質問

「テストはどこにあるか:commonTestと仲間たち」レッスンは無料ですか?

はい。「テストはどこにあるか:commonTestと仲間たち」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Kotlin Multiplatform Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Kotlin Multiplatform Academyコースには全4レッスンが含まれています。

「テストはどこにあるか:commonTestと仲間たち」で何を学びますか?

共有テストとプラットフォーム固有テスト用のソースセットを学びます ブラウザで直接実行するハンズオンコードでKotlin Multiplatform Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Kotlin Multiplatform Academyを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのKotlin Multiplatform Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「テストはどこにあるか:commonTestと仲間たち」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このKotlin Multiplatform Academyレッスンでコードを書いて実行できますか?

はい。すべてのKotlin Multiplatform Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. shared ModuleとApp Modules
  2. commonMain、androidMain、iosMain
  3. 共有build.gradle.ktsを読む
  4. テストはどこにあるか:commonTestと仲間たち
← Kotlin Multiplatform Academyに戻る