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
- LeeYoonSam/ClaudeSkillsForAndroidtheir own version, first seen Nov 19, 2025
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- LeeYoonSam/ClaudeSkillsForAndroid★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository40 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- android-accessibilitySkill
- android-adaptive-layoutsSkill
- android-adb-terminalSkill
- android-background-executionSkill
- android-bluetooth-bleSkill
- android-build-verificationSkill
- android-camerax-mlkitSkill
- android-ci-cd-expertSkill
- android-clean-architectureSkill
- android-code-review-expertSkill
- android-coroutines-expertSkill
- android-custom-drawing-canvasSkill
- android-design-system-m3Skill
- android-design-to-codeSkill
- android-detekt-expertSkill
- android-enterprise-securitySkill
- android-gemini-nanoSkill
- android-google-workspace-expertSkill
- android-gradle-expertSkill
- android-hardware-testingSkill
- android-jetpack-composeSkill
- android-kmp-compose-uiSkill
- android-kmp-platform-channelsSkill
- android-kmp-sharedSkill
- android-ktlint-formattingSkill
- android-lint-and-qualitySkill
- android-local-stt-ttsSkill
- android-location-mapsSkill
- android-macrobenchmarkSkill
- android-media3-exoplayerSkill
- android-media-and-image-expertSkill
- android-motion-animationsSkill
- android-navigation-expertSkill
- android-offline-firstSkill
- android-performance-auditSkill
- android-rag-localSkill
- android-screenshot-testingSkill
- android-security-hardenedSkill
- android-wear-os-composeSkill
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
- Very specific: line 33
Use @Test, @BeforeEach, and @DisplayName for clear tests.
- Distinctive: line 34
Rule: Prefer JUnit 5 for new projects, but JUnit 4 is common in legacy.
- Distinctive: line 38
Rule: Use MockK for Kotlin-first mocking.
- Very specific: line 47
Rule: Never use collect or first() in tests manually.
- Very specific: line 64
Rule: NEVER hardcode Dispatchers.IO or Main.
- Very specific: line 65
In Tests: Use StandardTestDispatcher or UnconfinedTestDispatcher.
- Distinctive: line 71
Standard: Test the Initial State → Trigger Action → Verify Final State and/or Side Effects.
- Very specific: line 72
Note: Ensure Dispatchers.setMain(testDispatcher) is called before and Dispatchers.resetMain() after tests.
- Distinctive: line 76
Standard: Test that data is correctly mapped and error handling is resilient.
- Very specific: line 77
Fakes: Use FakeLocalSource or FakeRemoteSource for complex integration tests.
- Distinctive: line 81
Standard: Test that the use case calls the repository and applies business rules correctly.
≈ “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.
Files
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
FlowandStateFlow. - 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@DisplayNamefor 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 ...andcoEvery { ... } returns ...for suspend functions.val repository = mockk<UserRepository>() coEvery { repository.getUser("123") } returns User("John")
3. Turbine (Flow Testing)
- Rule: Never use
collectorfirst()in tests manually. Use Turbine.flow.test { assertEquals(1, awaitItem()) assertEquals(2, awaitItem()) awaitComplete() }
🚀 Coroutine Testing (Essentials)
Use runTest
runTestskipsdelay()and ensures tests run fast and predictably.
Inject Dispatchers
- Rule: NEVER hardcode
Dispatchers.IOorMain. Inject them. - In Tests: Use
StandardTestDispatcherorUnconfinedTestDispatcher.
🧪 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 andDispatchers.resetMain()after tests.
2. Repositories
- Standard: Test that data is correctly mapped and error handling is resilient.
- Fakes: Use
FakeLocalSourceorFakeRemoteSourcefor 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
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
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.

