Add automated tests that pin real behaviour, covering edges, error paths and known regressions, in the project's own test style, fast and deterministic. Use for "write tests for", "add test coverage", "cover this module", "this has no tests".
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Write Tests?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/kinzarra-write-tests)
---
name: write-tests
description: Add automated tests that pin real behaviour, covering edges, error paths and known regressions, in the project's own test style, fast and deterministic. Use for "write tests for", "add test coverage", "cover this module", "this has no tests".
---
# Write tests
The result is a set of tests that would fail if the behaviour broke, runs the same way every time, and reads like a description of what the code promises.
## 1. Learn the project's test style
- Find the test command, the test folders and how tests are named, grouped and selected. Run the suite once and record its time and any failures that already exist.
- Read 3 to 5 existing tests near the target code. Copy their structure: setup helpers, fixtures and factories, assertion style, naming, how external services, time and randomness are replaced.
- Use the test framework and helpers the project already has. A new test library or a new pattern needs the task to ask for it.
## 2. Find the untested risk
Rank what to test by damage if it broke, not by line count:
1. Code that handles money, permissions, deletion, migration or data sent to other systems.
2. Code with many branches, parsing, date and time arithmetic, rounding, state machines, retries.
3. Code that changed often or was fixed often (read the file history) and code named in past bug reports.
4. Public entry points: endpoints, commands, exported functions, event handlers.
Use the coverage report when the project has one, to find branches never executed. Coverage shows what is not run; it does not show what is checked. Do not chase a percentage.
## 3. What to cover for each unit of behaviour
- **The main case**: typical input, the documented result.
- **Boundaries**: empty, one, many; zero, negative, the maximum and one past it; the first and last element; exactly at a limit.
- **Awkward input**: missing and null fields, wrong type, whitespace, very long strings, non-Latin text, duplicates, unsorted input, time zones, daylight saving shifts, the end of a month and of a year.
- **Error paths**: invalid input, no permission, not found, conflict, dependency timeout or failure. Assert the error type or code and that nothing was half-written.
- **State and order**: calling twice, calling out of order, repeated delivery of the same message, concurrent calls where the code claims to be safe.
- **Regressions**: one test for every bug fixed in this area, named for the behaviour.
## 4. How to write them
- One behaviour per test. The name states the condition and the expected result, so that a failure message alone says what broke.
- Arrange, act, assert, in that order, with the act being one call. Build only the data the test needs.
- Assert on outputs and observable effects (return value, stored record, emitted message, response). Do not assert on private methods or on the order of internal calls unless that order is the contract.
- Replace only what is slow, external or random: network, clock, random source, third-party services. Keep the project's own logic real. A test that checks only that a stub returned what it was told to return tests nothing: delete it.
- Deterministic: a fixed clock and seed, no sleeps, no dependence on test order, on the machine's locale or time zone, on the network, or on data left by another test. Each test creates and cleans its own state.
- Fast: a unit test runs in milliseconds. Put slow tests where the project keeps its slow or integration tests.
- No logic in tests: no loops with conditions, no copies of the production formula. Write expected values as literals.
- Use table-driven or parameterized tests for many inputs of one rule, in the project's way.
## 5. Prove the tests work
- Run each new test and see it pass. Then break the code under test on purpose (flip a condition, return early) and see the test fail; restore the code. A test that cannot fail is removed.
- Run the new tests 10 times, and in a different order when the runner allows it, to catch flakiness.
- Run the full suite and the linter. Record the suite time before and after; explain an increase of more than about 10 percent.
- A test that exposes a real bug stays. Report the bug; fix the production code only when the task allows it, otherwise mark the test as an expected failure in the project's way and explain why.
## 6. Report
1. **What is covered now**: the behaviours, grouped by module, with the test files.
2. **Counts**: tests added, the suite result (passed, failed, skipped) and its time before and after.
3. **Bugs found** while testing: file and line, the input, expected and actual.
4. **Left untested and why**: code that cannot be reached without a design change, with the change that would make it testable.
5. **Production code touched**, if any, and the reason.
Rules: do not weaken or delete existing tests to make the suite pass. Do not change production behaviour unless the task says so. Test data contains no real personal data and no real secrets. Do not commit, push or merge unless the task says so. When blocked, state exactly what is needed.