Test Writing
Write automated tests for existing or new functionality. Use this skill when tests are requested, including unit tests, integration tests, and end-to-end tests.
Best use case
Test Writing is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Write automated tests for existing or new functionality. Use this skill when tests are requested, including unit tests, integration tests, and end-to-end tests.
Teams using Test Writing should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/test-writing/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How Test Writing Compares
| Feature / Agent | Test Writing | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Write automated tests for existing or new functionality. Use this skill when tests are requested, including unit tests, integration tests, and end-to-end tests.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Skill: Test Writing
## Metadata
| Field | Value |
|-------|-------|
| **Skill ID** | SKL-0017 |
| **Version** | 2.0 |
| **Owner** | reviewer |
| **Inputs** | Target source files, STATE.md, DECISIONS.md, existing tests, PRD |
| **Outputs** | Test files, STATE.md updated |
| **Triggers** | `TEST_REQUESTED` |
---
## Purpose
Write tests that verify behavior, catch regressions, and serve as living documentation. Tests should explain what the code does and why.
---
## Procedure
1. **Read DECISIONS.md** — identify testing framework (Jest, pytest, Mocha, Swift Testing, JUnit4 + MockK, etc.), file location/naming conventions, established patterns. If none: recommend and log.
2. **Understand what to test:**
- Read source code thoroughly
- Identify the public interface
- Identify edge cases and error conditions
- Identify dependencies needing mocks
3. **Write tests in this order:**
- **Happy path:** Does it work with valid inputs?
- **Edge cases:** Boundaries, empty inputs, max values
- **Error cases:** Invalid inputs, missing data, network failures
- Each test must be independent — no test depends on another
4. **Naming convention:** `it("should [expected behavior] when [condition]")` — a failing test name tells you what broke without reading code.
5. **Verify tests run and pass:**
- Run test suite to confirm
- Test failures: determine if test bug or source bug
- Test bugs: fix the test
- Source bugs: report to Orchestrator for routing to fixer
6. **Update STATE.md** with test files created and results.
---
## Mobile Testing Guide
When the target is a mobile app, apply these platform-specific strategies in addition to the general procedure above.
### Testing Priority (all mobile platforms)
Follow the "testing trophy" — highest ROI first:
1. **ViewModel / business logic tests** — fastest to run, highest value per test
2. **Screenshot / snapshot tests** — one test catches visual regressions across themes, sizes, and modes
3. **UI smoke tests** — critical flows only (onboarding, core action, purchase); slow and brittle, so minimize
4. **Integration tests** — API + data layer
**Coverage targets:** 70-80% on ViewModels and business logic, 50-60% overall.
### Swift/iOS Testing
| Layer | Framework | What to test |
|-------|-----------|-------------|
| Unit (ViewModel) | Swift Testing (`@Test`, `#expect`) | State transitions, business logic, data transformations |
| Snapshot | swift-snapshot-testing (Point-Free) | View appearance across devices, Dynamic Type sizes, dark mode |
| UI | XCUITest | Critical user flows only (sign in, core action, navigation) |
- Use `@Test` and `#expect` (Swift Testing) for all new tests — not XCTest assertions
- Use `@MainActor` on ViewModel tests that touch UI state
- Mock dependencies via protocol conformance, not subclassing
- Pin CI to a specific Xcode/OS version for snapshot consistency
- Note: XCUITest and snapshot tests require a simulator — flag if unavailable
### Kotlin/Android Testing
| Layer | Framework | What to test |
|-------|-----------|-------------|
| Unit (ViewModel) | JUnit4 + MockK + Turbine | StateFlow emissions, use case logic, repository behavior |
| Snapshot | Roborazzi | Compose component screenshots across themes and font scales |
| UI | Compose Testing + Robolectric | Component rendering, user interactions, navigation |
- Use `runTest` from `kotlinx-coroutines-test` for coroutine tests
- Use Turbine's `.test {}` block for Flow assertions
- Use `createComposeRule()` for Compose UI tests
- Use MockK (`every`, `coEvery`) — not Mockito
- Robolectric runs Compose tests 10x faster than emulator — prefer it for CI
- Exclude generated code from coverage (R.class, BuildConfig, Hilt generated)
### React Native Testing
| Layer | Framework | What to test |
|-------|-----------|-------------|
| Unit | Jest | Business logic, utility functions, custom hooks |
| Component | React Native Testing Library | Component rendering, user interactions |
| E2E | Detox or Maestro | Full app flows on simulator/emulator |
---
## Constraints
- Never modifies source files — only creates/modifies test files
- Never writes tests that depend on execution order
- Always confirms testing framework from DECISIONS.md first
- Always confirms mobile testing framework (Swift Testing vs XCTest, JUnit4 vs JUnit5) before writing mobile tests
- Never mixes Swift Testing (`@Test`) with XCTest assertions in the same test file
- Reports source bugs to Orchestrator rather than fixing directly
---
## Primary Agent
reviewer
---
## Definition of Done
- [ ] Testing framework confirmed from DECISIONS.md
- [ ] Happy path, edge cases, and error cases covered
- [ ] Each test is independent and clearly named
- [ ] All tests pass
- [ ] Test files follow project conventions
- [ ] Mobile testing priority followed (ViewModel tests first) — if mobile project
- [ ] Platform-appropriate test framework used (Swift Testing / JUnit4+MockK / Jest) — if mobile project
- [ ] STATE.md updated
## Output Contract
| Field | Value |
|-------|-------|
| **Artifacts** | Test files (unit, integration, e2e) matching project conventions |
| **State Update** | `.claude/project/STATE.md` — mark task complete, log files modified |
| **Handoff Event** | `TASK_COMPLETED` (tests written, ready for review) |Related Skills
Copywriting
Write conversion-focused copy using proven frameworks (AIDA, PAS, BAB). Produces headlines, CTAs, landing page copy, email sequences, and micro-copy. Ensures copy matches brand voice and target audience.
User Acceptance Testing
Structured QA testing with four modes: diff-aware (auto-scoped to branch changes), full (systematic exploration), quick (30-second smoke test), and regression (compare against baseline). Produces health score, structured reports, and actionable bug lists. Use this skill when UAT is requested or a feature is ready for acceptance testing.
Problem Stress Test
Stress-test a startup or product idea against Uri Levine's problem-validation frameworks from "Fall in Love with the Problem, Not the Solution." Produces a ten-lens challenge report with scores and an advisory verdict (Strong / Needs Work / Weak). Use this skill when validating whether a problem is worth solving before committing resources. The user always decides — this skill advises, never blocks.
PRD Writing
Write a Product Requirements Document through user interview, including user stories, requirements, and acceptance criteria. Includes a Vision Challenge mode (CEO review) to ensure the right problem is being solved at the right scope before writing begins. Use this skill when a new PRD needs to be created for a project.
GDD Writing
Write a Game Design Document through user interview, incorporating established game design theory (MDA Framework, Bartle Player Types, 4-timescale gameplay loops, design pillars). Produces a structured GDD at docs/GDD.md. Parallels PRD Writing (SKL-0004) but is purpose-built for game projects.
Supply Chain Audit
Audit the dependency supply chain for security risks beyond what `npm audit` or `pip audit` catches. Analyzes dependency health, maintainer trust signals, typosquatting risk, and transitive dependency exposure.
SEO Audit
Audit web pages for search engine optimization: meta tags, heading hierarchy, structured data, image optimization, mobile-friendliness, and content quality. Complements SKL-0013 (Growth & Distribution) by validating what was built.
Pitch Deck
Create a structured pitch deck outline for investors, stakeholders, or partners. Covers problem, solution, market, traction, team, and ask. Natural output after PRD + Problem Stress Test validation.
Launch Checklist
Pre-launch validation covering everything deployment (SKL-0021) doesn't: analytics, error tracking, social meta, legal pages, email setup, DNS, SSL, and go-live readiness. Produces a launch readiness report with pass/fail checklist. Use this skill before going live on any project.
Insecure Defaults Detection
Detect insecure default configurations, hardcoded credentials, fail-open security patterns, and dangerous default values in application code and configuration files. Complements SKL-0015 (Security Audit) by focusing on configuration-level vulnerabilities that dependency scanners miss.
Differential Security Review
Security-focused review of code changes using git diff analysis. Identifies security implications of recent modifications — new attack surfaces, removed protections, changed auth logic, and risky refactors. Complements SKL-0016 (Code Review) with a security lens on diffs.
Competitor Analysis
Structured competitor research: features, pricing, positioning, gaps, and differentiation strategy. Feeds into PRD Writing (SKL-0004) and Problem Stress Test (SKL-0027) with better market context.