Logo Kotlin Testing Kmp

Kotlin Testing Kmp

Cộng đồng
mmiani
kotlin-testing-kmp

Use when designing, implementing, or reviewing tests in KMP projects — unit tests, instrumented tests, Compose Multiplatform UI tests, test doubles, test strategy, stability, performance, and screenshot testing.

Add to TypingMind

Tổng quan

Nhà phát hànhmmiani
Kho mãkotlin-kmp-claude-agent-skills
Tên kỹ năngkotlin-testing-kmp
Sao
89
Bản fork
9
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépApache-2.0
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Hướng dẫn có đủ mọi thứ cần thiết

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được mmiani công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Kotlin Testing Kmp trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/mmiani/kotlin-kmp-claude-agent-skills/tree/main/skills/kotlin-testing-kmp
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/mmiani/kotlin-kmp-claude-agent-skills.git /tmp/kotlin-kmp-claude-agent-skills
mkdir -p .claude/skills
cp -r /tmp/kotlin-kmp-claude-agent-skills/skills/kotlin-testing-kmp .claude/skills/kotlin-testing-kmp
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Kotlin Testing Kmp trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Kotlin Testing Kmp ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Kotlin Testing Kmp với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Kotlin Multiplatform Testing

Use this skill when designing, implementing, or reviewing tests in a Kotlin Multiplatform project.

This skill is intentionally strict. Its purpose is to keep the test suite fast, trustworthy, behavior-focused, and aligned with Android’s testing guidance while still respecting shared KMP boundaries and Compose Multiplatform testing patterns.

Primary goals

The testing strategy should optimize for:

  • strong confidence in business logic
  • fast feedback from local/unit tests
  • clear separation between local, Robolectric, instrumented, and UI tests
  • behavior-focused tests instead of implementation-detail tests
  • appropriate use of test doubles
  • stable and performant larger tests
  • isolated testing of shared KMP logic
  • practical Compose Multiplatform UI test coverage
  • targeted screenshot testing where visual regressions matter

Do not optimize for raw coverage percentages alone. Optimize for confidence, speed, signal quality, and maintainability.


Official defaults to prefer

Unless the project has a strong reason not to, prefer these defaults:

  • many small local/unit tests
  • fewer integration tests
  • fewer end-to-end/UI tests than lower-level tests
  • tests focused on user-visible behavior and business outcomes
  • use of test doubles to isolate dependencies
  • kotlin.test for assertions and test declarations in shared KMP test source sets — this is the cross-platform test API recommended by JetBrains and works across JVM, native, and JS/Wasm targets
  • local tests in src/test (JVM-side tests in Android modules)
  • Android instrumented tests in src/androidTest
  • Robolectric only when Android framework behavior is needed but device execution is not necessary
  • common Compose Multiplatform UI tests where the behavior is truly shared
  • stable UI tests with clear synchronization and controlled environment setup
  • screenshot tests for important visual surfaces when appearance regressions matter

Test strategy defaults

1. Testing pyramid

Prefer a pyramid-shaped suite:

  • many unit tests
  • fewer integration tests
  • fewer UI/end-to-end tests

Review expectation:

  • lower-level tests should catch most regressions
  • larger tests should validate integration and user workflows, not replace unit coverage

Flag as a concern when:

  • most confidence depends on slow UI tests
  • business logic is only exercised through end-to-end flows
  • the suite is top-heavy and expensive to run

2. Behavior over implementation detail

Prefer tests that validate:

  • observable outputs
  • state transitions
  • user-visible effects
  • business rules

Be cautious with tests that lock down:

  • internal private structure
  • implementation-specific sequencing that users do not observe
  • framework internals

Flag as a concern when:

  • tests fail after harmless refactors
  • mocks assert incidental calls instead of real behavior
  • UI tests are verifying widget internals rather than actual interaction outcomes

Test-scope review dimensions

3. What should be tested first

Prioritize tests for:

  • business rules
  • domain/use-case behavior
  • repository coordination logic
  • DTO/domain/UI mapping
  • state-holder transitions
  • failure and retry handling
  • navigation decision logic where important
  • shared UI behavior that is meaningful across targets

Flag as a concern when:

  • trivial pass-through code is heavily tested while important rules are not
  • mapping and error paths are untested
  • state transitions are inferred rather than verified

4. Local unit tests

Local tests should be the default choice for fast feedback.

For shared KMP modules, tests in commonTest (using kotlin.test) run on all declared targets — JVM, native, JS/Wasm — making them the correct layer for shared business logic. Do not confuse commonTest (shared KMP tests) with src/test (Android/JVM-local tests).

Check whether:

  • pure Kotlin/shared logic is tested in commonTest using kotlin.test, not pushed into Android-specific test layers
  • Android-specific behavior is tested in src/test (local JVM) or src/androidTest (instrumented), not in shared test source sets
  • test setup avoids Android device/emulator dependency when unnecessary
  • most business logic tests live in the lowest practical test layer

Review expectations:

  • shared logic in KMP should be exercised in commonTest first, before platform-specific layers
  • src/test remains the main home for fast-running JVM-side tests on Android-only modules
  • local tests are preferred unless the behavior truly needs Android runtime support

Flag as a concern when:

  • shared business logic is only tested in Android-specific layers (src/androidTest) without reason
  • the suite pays emulator/device cost for logic that could be a commonTest unit test
  • kotlin.test is not used in shared source sets — shared tests depend on JUnit directly, breaking non-JVM targets

4a. kotlin.test for shared source sets

In KMP projects, shared test source sets (e.g., commonTest) should use kotlin.test for assertions and test structure. kotlin.test provides @Test, assertEquals, assertNotNull, assertFailsWith, and other essentials that compile correctly for all KMP targets (JVM, native, JS, Wasm).

Check whether:

  • shared test code uses kotlin.test rather than JUnit or platform-specific assertion libraries
  • kotlin.test is declared as a dependency in the commonTest source set
  • platform-specific test libraries (JUnit, XCTest wrappers) are added only in platform-specific test source sets when needed

Flag as a concern when:

  • JUnit annotations or assertions appear in commonTest without a JVM-only source set constraint
  • shared tests fail on native or JS targets because of JVM-specific test infrastructure
  • kotlin.test is absent from a KMP project's test dependencies despite having shared business logic

5. Robolectric usage

Robolectric is an Android-only testing tool. It is not available in KMP shared test source sets — it can only be used in Android-specific test source sets (src/test in an Android module, or an androidUnitTest source set in a KMP module). Do not attempt to configure Robolectric in commonTest.

Robolectric is useful when Android-dependent behavior must be exercised on the JVM without a real device or emulator.

Check whether:

  • Robolectric is used for Android framework interactions that do not require full device/emulator fidelity
  • it is placed in Android-specific test source sets, not shared KMP test source sets
  • it is not used as a default for tests that could be plain local tests or kotlin.test unit tests
  • the project uses it intentionally rather than as a catch-all compromise

Flag as a concern when:

  • Robolectric is used for pure business logic that does not interact with Android APIs
  • device-only behavior is assumed to be fully proven by Robolectric alone
  • the suite becomes slow and brittle because Robolectric is overused
  • Robolectric dependencies appear in shared KMP source sets

6. Instrumented tests

Instrumented tests should cover behavior that genuinely needs a real Android runtime, emulator, or device.

Check whether:

  • Android integration behavior is validated in src/androidTest
  • tests that need framework/runtime fidelity are placed here
  • instrumented tests are selective rather than the default

Good candidates:

  • platform integration
  • app-component interactions
  • behavior that depends on real Android runtime semantics
  • high-value UI flows

Flag as a concern when:

  • most feature validation lives only in instrumented tests
  • instrumented tests are used for logic that should be local
  • test layering is blurry and costly

7. Compose Multiplatform UI tests

Compose Multiplatform supports shared UI testing.

Check whether:

  • shared UI behavior is tested in common code when it is genuinely shared
  • runComposeUiTest is used for common Compose Multiplatform UI tests (note: as of mid-2025, runComposeUiTest requires @OptIn(ExperimentalTestApi::class); verify stability status against the current Compose Multiplatform release)
  • platform-specific setup is added only when required
  • shared UI tests focus on semantics and observable behavior

Flag as a concern when:

  • shared UI can only be validated through Android-only tests without reason
  • common UI tests are skipped despite heavily shared Compose behavior
  • tests depend too much on implementation details instead of semantics

8. AndroidX Test setup discipline

AndroidX Test setup should be coherent and intentional.

Check whether:

  • test runners, rules, and AndroidX Test dependencies are configured consistently
  • instrumented tests use the standard test infrastructure instead of ad hoc setup
  • test environment setup is centralized enough to avoid drift

Flag as a concern when:

  • instrumented test setup differs arbitrarily across modules
  • runner/rule configuration is duplicated or inconsistent
  • test infrastructure itself becomes hard to trust

Test doubles

9. Appropriate test-double choice

Choose test doubles deliberately.

Common categories:

  • fake
  • mock
  • stub
  • spy

Prefer:

  • fakes for repositories, data sources, and meaningful behavior simulation
  • stubs for simple fixed responses
  • mocks only when interaction verification is actually the point
  • spies sparingly

Flag as a concern when:

  • everything is mocked by default
  • tests are interaction-heavy but behavior-light
  • a fake would express the scenario more clearly than a deep mock tree

10. Dependency isolation

Check whether:

  • tests isolate external systems appropriately
  • network, database, file, and platform dependencies are replaced when the test does not need them
  • doubles reduce flakiness and improve speed

Flag as a concern when:

  • tests depend on real external services unnecessarily
  • fake/test data behavior diverges so much from production that the test misleads
  • the chosen double makes the test harder to understand

Stability and performance for larger tests

11. Big-test stability

Android’s guidance treats stability as a first-class quality attribute for larger tests.

Check whether:

  • tests control asynchronous work predictably
  • environment setup is repeatable
  • test state is isolated between runs
  • flakiness sources are identified and reduced
  • retries are not hiding real nondeterminism

Flag as a concern when:

  • UI/integration tests pass only intermittently
  • timing assumptions replace synchronization
  • global shared state leaks between tests

12. Performance of instrumented tests

Instrumented tests should be optimized because they are expensive.

Check whether:

  • the instrumented suite stays focused on high-value scenarios
  • setup and teardown are not wasteful
  • large tests are not duplicated unnecessarily across many layers
  • performance-sensitive test suites are monitored and trimmed

Flag as a concern when:

  • large tests are used where local tests would suffice
  • startup/setup costs dominate every test
  • the suite becomes too slow to run regularly

UI testing guidance

13. UI tests should validate behavior

UI tests should focus on what the user can do and observe.

Check whether:

  • assertions reflect visible behavior or meaningful semantics
  • user actions are modeled realistically
  • UI tests validate flows, not incidental structure

Flag as a concern when:

  • tests lock onto fragile implementation details
  • the suite checks internal tree shapes with little user value
  • behavior is under-tested while low-value rendering details dominate

14. Screenshot testing

Screenshot tests are useful for detecting visual regressions on stable surfaces.

Check whether:

  • screenshots are applied to important visual states
  • expected variants are intentional and controlled
  • screenshots complement, rather than replace, behavioral tests
  • visual baselines are maintained carefully

Good candidates:

  • design-system components
  • stable destination screens
  • major adaptive-layout variants
  • key theme or locale states where appearance matters

Flag as a concern when:

  • screenshot tests are used as the main correctness signal for behavior
  • baselines churn constantly because surfaces are too unstable
  • too many low-value screenshots make maintenance noisy

KMP-specific review dimensions

15. Shared-vs-platform test placement

Test-source-set placement should mirror code-source-set placement:

  • commonTest (using kotlin.test): shared business logic, domain rules, shared repository behavior, Compose Multiplatform UI behavior
  • Android src/test (JUnit/Robolectric): Android-specific logic, ViewModel behavior where ViewModel is Android-only
  • Android src/androidTest: Android integration, real framework behavior, UI flows on Android
  • iOS/native test source sets: iOS-platform-specific behavior

Check whether:

  • shared behavior is tested in commonTest using kotlin.test
  • Android-specific behavior remains in Android test layers
  • platform-specific assertions do not leak into shared tests without reason
  • kotlin.test is used consistently in shared source sets (not JUnit4/JUnit5 directly, which are JVM-only)

Flag as a concern when:

  • shared logic is only tested in Android-specific layers
  • JUnit annotations appear in commonTest (breaks non-JVM compilation targets)
  • platform-specific test setup (context, activity, application) pollutes shared test code
  • the team does not know which test layer owns which behavior

16. State-holder and flow testing

Check whether:

  • state-holder outputs are tested deterministically
  • loading, success, empty, error, retry, and partial-data paths are covered
  • one-time events are tested separately from persistent state
  • flow-based logic is verified without over-relying on UI tests

Flag as a concern when:

  • state behavior is inferred only through UI rendering
  • event emission is untested
  • async/state tests are timing-based rather than deterministic

17. Repository and mapping testing

Check whether:

  • repositories are tested for coordination logic, source-of-truth behavior, and error handling
  • mapping is tested directly
  • test doubles are used where they provide clarity

Flag as a concern when:

  • mapping bugs can only be caught through broad integration tests
  • repository conflict resolution is untested
  • data-layer correctness depends mainly on manual QA

Severity framework

High severity

Likely to undermine trust in the suite.

Examples:

  • business logic only covered by UI/instrumented tests
  • highly flaky big tests
  • no clear separation between local and instrumented tests
  • shared KMP logic untested or only tested through one platform
  • unstable UI tests driven by timing assumptions

Medium severity

Workable, but likely to create maintenance cost.

Examples:

  • overuse of mocks
  • Robolectric used too broadly
  • screenshot coverage is noisy or poorly targeted
  • instrumented suite too large for its value
  • important state transitions missing direct tests

Low severity

Structurally acceptable but worth improving.

Examples:

  • test naming could be clearer
  • some fakes could replace mocks
  • preview/screenshot variants could be better targeted

Required output format

When performing the review, respond with:

  1. Testing summary

    • overall strategy
    • test pyramid shape
    • local / Robolectric / instrumented / UI / screenshot split
    • shared-vs-platform test placement
  2. What is structurally sound

    • concrete strengths only
  3. Issues by review dimension

    • strategy and pyramid
    • what is being tested
    • local tests
    • Robolectric usage
    • instrumented tests
    • Compose Multiplatform UI tests
    • AndroidX Test setup
    • test doubles
    • stability
    • performance
    • UI behavior tests
    • screenshot tests
    • shared-vs-platform placement
    • state-holder/flow tests
    • repository/mapping tests
  4. Severity for each issue

    • high / medium / low
  5. Concrete recommendations

    • which tests should move down the pyramid
    • where to replace mocks with fakes/stubs
    • what should become local vs instrumented
    • what shared UI should be covered in common tests
    • where screenshot tests add value
    • how to reduce flakiness and runtime
  6. Suggested target structure

    • proposed test-layer split if useful
  7. Open risks

    • migration cost
    • flakiness still to investigate
    • platform-specific validation still required

Tone

Be direct and practical. Do not praise a large suite just because it has many tests. If the testing strategy is weak, say why clearly.


Anti-patterns to flag aggressively

  • top-heavy test suites dominated by UI/end-to-end tests
  • business logic verified only through instrumented/UI tests
  • unstable tests that rely on sleeps or timing guesses
  • heavy mock usage where fakes would be clearer
  • Android-specific assumptions inside shared KMP tests
  • screenshot tests used as a substitute for behavior tests
  • duplicated large tests across multiple layers
  • expensive instrumented tests with low signal

References

Câu hỏi thường gặp

Kỹ năng AI Kotlin Testing Kmp làm được gì?

Use when designing, implementing, or reviewing tests in KMP projects — unit tests, instrumented tests, Compose Multiplatform UI tests, test doubles, test strategy, stability, performance, and screenshot testing.

Vì sao nên dùng Kotlin Testing Kmp trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Kotlin Testing Kmp là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Kotlin Testing Kmp trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/mmiani/kotlin-kmp-claude-agent-skills/tree/main/skills/kotlin-testing-kmp. TypingMind đọc tệp SKILL.md rồi cài đặt kỹ năng để bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Kotlin Testing Kmp?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Kotlin Testing Kmp với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Kotlin Testing Kmp với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Kotlin Testing Kmp có miễn phí không?

Có. Kỹ năng này được mmiani phát hành trên GitHub theo giấy phép Apache-2.0. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇