create-unit-test
Standardize unit testing in Kotlin/Android projects with Robolectric and the Arrange-Act-Assert pattern.
Install
mkdir -p .claude/skills/create-unit-test && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/2317" && unzip -o skill.zip -d .claude/skills/create-unit-test && rm skill.zipInstalls to .claude/skills/create-unit-test
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Create and run unit tests following the project's architecture and guidelines (Robolectric, naming, location).Key capabilities
- →Analyzing code for test planning
- →Setting up Robolectric for Android components
- →Implementing tests using Arrange-Act-Assert pattern
- →Executing unit tests via Gradle
- →Diagnosing test failures from XML reports
How it works
The skill guides the user through planning, file setup, and implementation of unit tests, mandating Robolectric for Android components and providing specific Gradle commands for execution.
Inputs & outputs
When to use create-unit-test
- →Create a unit test for a new class
- →Refactor existing test files
- →Debug failing Android tests
About this skill
Create Unit Test
This skill guides the creation of unit tests to ensuring consistency and correctness.
Workflow
-
Analyze and Plan:
- Goal: Understand what needs testing.
- Action: Examine the source code.
- Action: Identify "happy path" cases (core functionality).
- Action: Identify "error cases" and "edge cases" based on likelihood.
- Action: Do not suggest implementation details unless asked; focus on behavior.
-
Setup Test File:
- Naming:
[OriginalClassName]Test.kt. - Location:
[module]/src/test/java/[package/path]/. - Runner: If testing Android components, you MUST use Robolectric.
- Mocking: Prefer creating Fakes over Mocks or patches. Use Mocks only if Fakes are too complex.
- Naming:
-
Implement Tests:
- Write clear, descriptive test methods.
- Follow the "Arrange-Act-Assert" pattern.
- Ensure all resources (strings, themes) are properly mocked or provided via Robolectric.
-
Run Tests:
- Command:
./gradlew :[module]:testDebugUnitTest - Example:
./gradlew :database:testDebugUnitTest - Tip: Before any commit, run
./gradlew testDebugUnitTestto ensure everything passes.
- Command:
-
Handle Failures:
- Goal: Diagnose and fix issues.
- Action: If a test fails, locate the full error report.
- Path:
[module]/build/test-results/testDebugUnitTest/TEST-[package.name.TestClassName].xml. - Example:
app/build/test-results/testDebugUnitTest/TEST-com.anysoftkeyboard.janus.app.MainActivityTest.xml.
Guidelines
- Consistency: Always place tests in the
testsource set, notandroidTest(unless specifically writing instrumentation tests, which is rare for this skill). - Reliability: Avoid flaky tests. Ensure deterministic behavior.
When not to use it
- →For instrumentation tests
- →When deterministic behavior cannot be ensured
Prerequisites
Limitations
- →Requires Robolectric for Android components
- →Tests must be deterministic
How it compares
It enforces project-specific architectural guidelines and naming conventions rather than providing generic testing advice.
Compared to similar skills
create-unit-test side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| create-unit-test (this skill) | 2 | 7mo | No flags | Intermediate |
| survey-sdk-audit | 3 | 27d | Review | Intermediate |
| android-kotlin | 7 | 4mo | No flags | Intermediate |
| android-jetpack-compose-expert | 4 | 4mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
You might also like
survey-sdk-audit
PostHog
Audit PostHog survey SDK features and version requirements
android-kotlin
alinaqi
Android Kotlin development with Coroutines, Jetpack Compose, Hilt, and MockK testing
android-jetpack-compose-expert
sickn33
Expert guidance for building modern Android UIs with Jetpack Compose, covering state management, navigation, performance, and Material Design 3.
testing-android-code
bitwarden
This skill should be used when writing or reviewing tests for Android code in Bitwarden. Triggered by "BaseViewModelTest", "BitwardenComposeTest", "BaseServiceTest", "stateEventFlow", "bufferedMutableSharedFlow", "FakeDispatcherManager", "expectNoEvents", "assertCoroutineThrows", "createMockCipher", "createMockSend", "asSuccess", "Why is my Bitwarden test failing?", or testing questions about ViewModels, repositories, Compose screens, or data sources in Bitwarden.
kotlin-coroutines
vitorpamplona
Advanced Kotlin coroutines patterns for AmethystMultiplatform. Use when working with: (1) Structured concurrency (supervisorScope, coroutineScope), (2) Advanced Flow operators (flatMapLatest, combine, merge, shareIn, stateIn), (3) Channels and callbackFlow, (4) Dispatcher management and context switching, (5) Exception handling (CoroutineExceptionHandler, SupervisorJob), (6) Testing async code (runTest, Turbine), (7) Nostr relay connection pools and subscriptions, (8) Backpressure handling in event streams. Delegates to kotlin-expert for basic StateFlow/SharedFlow patterns. Complements nostr-expert for relay communication.
trail-sense-android-tests
kylecorry31
Add UI automation tests to Trail-Sense Android app using AutomationLibrary. Use when asked to create, add, write, or implement automated tests, UI tests, integration tests, or androidTests for Trail Sense tools. Covers test class structure, AutomationLibrary functions, and testing patterns.