home / skills / shotaiuchi / dotclaude / test-unit
This skill helps you create thorough unit tests for individual functions and classes with proper mocks, assertions, and coverage.
npx playbooks add skill shotaiuchi/dotclaude --skill test-unitReview the files below or copy the command above to add this skill to your agents.
---
name: test-unit
description: >-
Unit test creation. Apply when writing isolated tests for individual
functions, methods, and classes with proper mocking, assertions, and
coverage of happy paths and error conditions.
user-invocable: false
---
# Unit Tests
Write unit tests for individual functions, methods, and classes in isolation.
## Test Creation Checklist
### Function/Method Isolation
- Identify all external dependencies to mock or stub
- Ensure each test exercises exactly one unit of behavior
- Verify test independence (no shared mutable state between tests)
- Check that setup/teardown properly resets test context
- Confirm no reliance on execution order
### Assertion Completeness
- Assert return values for all meaningful inputs
- Verify state changes on mutable objects after method calls
- Check that expected exceptions are thrown with correct types and messages
- Assert side effects (method calls on collaborators, events emitted)
- Validate output structure, not just existence
### Happy Path Coverage
- Cover the primary success scenario end-to-end
- Test with typical/representative input values
- Verify correct behavior with valid boundary inputs
- Check default parameter behavior
- Test idempotent operations for consistent results
### Error Condition Coverage
- Test with invalid, null, and out-of-range inputs
- Verify graceful handling of dependency failures
- Check timeout and cancellation behavior
- Test concurrent access if applicable
- Validate error messages and error codes returned
## Output Format
Report test plan with priority ratings:
| Priority | Description |
|----------|-------------|
| Must | Core functionality tests that prevent regressions |
| Should | Important paths that cover common usage patterns |
| Could | Additional coverage for less common scenarios |
| Won't | Out of scope or covered by other test types |
This skill helps create focused unit tests for individual functions, methods, and classes with clear mocking, assertions, and prioritized test plans. It emphasizes isolation, complete assertions, and coverage of both happy paths and error conditions. The output is a prioritized test plan suitable for immediate implementation in a test suite.
It inspects function signatures, dependencies, and side effects to identify what to mock or stub and which behaviors to assert. It produces a checklist and a prioritized test matrix (Must/Should/Could/Won't) covering return values, state changes, exceptions, side effects, boundaries, and failure modes. The skill outputs concise test cases and setup/teardown guidance to ensure independence and reproducibility.
How do I decide what to mock?
Mock external systems, I/O, and slow or non-deterministic dependencies. Keep collaborators mocked so each test exercises only the unit under test.
What makes a test Must priority?
Must tests cover core functionality that would cause regressions if broken: main return values, essential side effects, and error conditions users rely on.
How many assertions per test are acceptable?
Prefer a small number of focused assertions that validate a single behavior; use multiple assertions when they verify different observable aspects of the same behavior.