writing-unit-tests — Claude Code skill for unit tests and setup
Guides an agent through writing or revising unit tests around observable behavior. Useful for flaky tests, confusing cases, and new test coverage.
npx skills add riekelt/principal-engineer --skill writing-unit-tests -a claude-codeWhat writing-unit-tests does
The skill treats each unit test as a claim about what callers can observe. It recommends a separate, clearly named test for each behavior, with expected values worked out independently of production calculations. Tests should exercise the public contract rather than inspect private state or routine call order.
For repeatable results, it calls for isolating time, randomness, network access, and filesystem work, with mocks placed at boundaries to external resources. Replace timed sleeps with checks for an observable condition and a deadline. The principal-engineering skill is a prerequisite; testing-changes determines which tests a code change needs. If a test mostly wires up mocks, the tested boundary may need to move or be covered by an integration test instead.
What it helps with
- split multiple behavioral claims into focused tests
- replace sleep-based waiting with condition checks
- remove mocks of code owned by the project
- isolate tests from real time and randomness
- verify expected values without reproducing production calculations
Example prompts for the agent
- Rewrite this unit test to check the public contract and state its claim in the test name.
- Diagnose this flaky test and replace its timed wait with a condition-based check.
- Add separate tests for the success case and the typed failure.
How to install writing-unit-tests
1Skills CLI (Vercel)
npx skills add riekelt/principal-engineer --skill writing-unit-tests -a claude-code2Manually: put the files in place
~/.claude/skills/writing-unit-tests/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/writing-unit-tests/
1Skills CLI (Vercel)
npx skills add riekelt/principal-engineer --skill writing-unit-tests -a codex2Manually: put the files in place
.agents/skills/writing-unit-tests/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add riekelt/principal-engineer --skill writing-unit-tests -a cursor2Manually: put the files in place
.cursor/skills/writing-unit-tests/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install riekelt/principal-engineer writing-unit-tests2Manually: put the files in place
.github/skills/writing-unit-tests/SKILL.md1Skills CLI (Vercel)
npx skills add riekelt/principal-engineer --skill writing-unit-tests -a gemini-cli2Platform CLI
gemini skills install https://github.com/riekelt/principal-engineer --path plugins/principal-engineer/skills/writing-unit-testsManually: put the files in place
.devin/skills/writing-unit-tests/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add riekelt/principal-engineer --skill writing-unit-tests -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about writing-unit-tests
How do I install writing-unit-tests in Claude Code?
Run npx skills add riekelt/principal-engineer --skill writing-unit-tests -a claude-code. The skill file is available at ~/.claude/skills/writing-unit-tests/SKILL.md.
What does writing-unit-tests do?
It guides an agent to write unit tests around observable behavior, with one claim per test. It favors public contracts and mocks at boundaries to resources outside the code's ownership.
What should I install before using the skill?
The skill requires principal-engineering first. testing-changes governs which tests are needed for a particular change.