agentleFS
prasad-vennamprasad-vennam/Awesome-Android-AI-Agent-Skills/skills/android-unit-testing/SKILL.md

android-unit-testing

Skill11 starsChanged 8 months agoMITView on GitHub

Use when writing or fixing unit tests, mocking objects, or testing reactive flows in Android.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 5 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use @Test, @BeforeEach, and @DisplayName for clear tests.

    line 33
  2. Distinctive:

    Rule: Prefer JUnit 5 for new projects, but JUnit 4 is common in legacy.

    line 34
  3. Distinctive:

    Rule: Use MockK for Kotlin-first mocking.

    line 38
  4. Very specific:

    Rule: Never use collect or first() in tests manually.

    line 47
  5. Very specific:

    Rule: NEVER hardcode Dispatchers.IO or Main.

    line 64
  6. Very specific:

    In Tests: Use StandardTestDispatcher or UnconfinedTestDispatcher.

    line 65
  7. Distinctive:

    Standard: Test the Initial State → Trigger Action → Verify Final State and/or Side Effects.

    line 71
  8. Very specific:

    Note: Ensure Dispatchers.setMain(testDispatcher) is called before and Dispatchers.resetMain() after tests.

    line 72
  9. Distinctive:

    Standard: Test that data is correctly mapped and error handling is resilient.

    line 76
  10. Very specific:

    Fakes: Use FakeLocalSource or FakeRemoteSource for complex integration tests.

    line 77
  11. Distinctive:

    Standard: Test that the use case calls the repository and applies business rules correctly.

    line 81

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Android Unit Testing Excellence 🧪🛡️

The ultimate guide to writing robust, reliable, and maintainable unit tests for Android applications using modern tools like MockK, Turbine, and Coroutine Test.

⚡ When to Use

  • Business Logic Verification: Testing Use Cases or ViewModels.
  • Data Layer Testing: Testing Repositories or Data Sources (with Fakes).
  • Reactive Stream Testing: Verifying emitted values from Flow and StateFlow.
  • Logic Refactoring: Ensuring no regressions during code changes.
  • TDD (Test-Driven Development): Writing tests before implementation.

🏗️ Core Tools

1. JUnit 5 (Modern Standard)

  • Use @Test, @BeforeEach, and @DisplayName for clear tests.
  • Rule: Prefer JUnit 5 for new projects, but JUnit 4 is common in legacy.

2. MockK (Power Mocking)

  • Rule: Use MockK for Kotlin-first mocking.
  • Shorthand: every { ... } returns ... and coEvery { ... } returns ... for suspend functions.
    val repository = mockk<UserRepository>()
    coEvery { repository.getUser("123") } returns User("John")

3. Turbine (Flow Testing)

  • Rule: Never use collect or first() in tests manually. Use Turbine.
    flow.test {
        assertEquals(1, awaitItem())
        assertEquals(2, awaitItem())
        awaitComplete()
    }

🚀 Coroutine Testing (Essentials)

Use runTest

  • runTest skips delay() and ensures tests run fast and predictably.

Inject Dispatchers

  • Rule: NEVER hardcode Dispatchers.IO or Main. Inject them.
  • In Tests: Use StandardTestDispatcher or UnconfinedTestDispatcher.

🧪 Testing Patterns

1. ViewModels

  • Standard: Test the Initial State → Trigger Action → Verify Final State and/or Side Effects.
  • Note: Ensure Dispatchers.setMain(testDispatcher) is called before and Dispatchers.resetMain() after tests.

2. Repositories

  • Standard: Test that data is correctly mapped and error handling is resilient.
  • Fakes: Use FakeLocalSource or FakeRemoteSource for complex integration tests.

3. Domain Use Cases

  • Standard: Test that the use case calls the repository and applies business rules correctly.

📦 Assertion Libraries

  • Truth (from Google): Fluent, readable assertions.
  • AssertJ: Extremely powerful and comprehensive.
  • Kotest Assertions: Native Kotlin syntax (e.g., user.name shouldBe "John").

🚀 Testing Checklist

  • Method Names: Use descriptive names like test_whenQueryChanged_updatesState.
  • One Assertion per Test: (Ideally) One logical assertion per test for better failure isolation.
  • Arrange-Act-Assert (AAA): Follow this structure for readability.
  • Verify Mocks: Check if expected methods were called using verify { ... }.

🔗 Related Resources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.