Skip to content
Skills Library
Programming · Testing

unit-testing

/unit-testing

Writes unit tests for code that already exists — choosing what deserves a test, what the cases are, and how to assert without welding the test to the implementation. Use this whenever the user asks for tests, unit tests, more coverage, or tests for a specific function or module, and also when adding to untested code where a characterization test is needed first. For building new code test-first, use test-driven-development.

Author
OKHP3 ↗
Repository
skillz ↗
Licence
MIT
Last repository change
25.10.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 25.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Writes unit tests for code that already exists — choosing what deserves a test, what the cases are, and how to assert without welding the test to the implementation. Use this whenever the user asks for tests, unit tests, more coverage, or tests for a specific function or module, and also when adding to untested code where a characterization test is needed first. For building new code test-first, use test-driven-development.

Original author description

Writes unit tests for code that already exists — choosing what deserves a test, what the cases are, and how to assert without welding the test to the implementation. Use this whenever the user asks for tests, unit tests, more coverage, or tests for a specific function or module, and also when adding to untested code where a characterization test is needed first. For building new code test-first, use test-driven-development.

How it works

  1. 1. Decide what deserves a test
  2. 2. Pick the seam
  3. 3. Enumerate cases before writing any
  4. 4. Write tests that survive refactoring
  5. 5. Testing code that was not built for it
  6. 6. Keep the suite trustworthy
Original SKILL.md headings · 97 lines, 786 words
SKILL.md preview
---
name: unit-testing
description: Writes unit tests for code that already exists — choosing what deserves a test, what the cases are, and how to assert without welding the test to the implementation. Use this whenever the user asks for tests, unit tests, more coverage, or tests for a specific function or module, and also when adding to untested code where a characterization test is needed first. For building new code test-first, use test-driven-development.
license: MIT
---

# Unit testing

A test earns its place by failing when something breaks and staying quiet otherwise. A test
that never fails is documentation with a runtime cost; a test that fails on every refactor is a
tax. Both get deleted eventually, and the second one takes the good tests' credibility with it.

Coverage is not the goal. Coverage measures which lines ran, not whether anything was checked —
a suite that executes everything and asserts nothing scores beautifully and catches nothing.

## 1. Decide what deserves a test

In descending order of value:

1. **Logic with branches** — conditionals, loops, calculations, parsing, state transitions
2. **Anything that has broken before** — bugs cluster; a fixed bug without a test will return
3. **Boundaries** — where data is validated, converted, or crosses a system edge
4. **Contracts other code relies on** — a public API's shape and its documented failure modes

Not worth it: generated code, thin pass-throughs, framework behaviour, getters, and anything
where the test would restate the implementation line for line.

**Done when:** you can say why each planned test exists, in terms of a failure it would catch.

## 2. Pick the seam

Test at the smallest **stable** interface that exposes the behaviour, not necessarily the
smallest unit. A private function extracted for tidiness is an implementation detail; testing
it directly freezes a decision you should be free to change.

If a behaviour is only reachable through six layers of setup, that is a design signal. Note it,
and test at the level that is reachable rather than mocking your way down.

**Done when:** the seam is one a caller would actually use.

## 3. Enumerate cases before writing any

Go through these deliberately — the value of a test suite is mostly in the cases people forget:

- **Typical:** the ordinary, realistic input
- **Empty:** zero items, empty string, no match, null where permitted
- **One:** the case where off-by-one hides
- **Many:** enough to expose ordering, pagination, accumulation
- **Boundary:** exactly at the limit, one either side
- **Invalid:** wrong type, wrong shape, out of range. What *should* happen? Assert that.
- **Duplicate / out of order:** for anything collection- or sequence-shaped
- **Failure of a dependency:** timeout, error, partial result

**Done when:** you have a written case list, with the ones you are deliberately skipping noted.

## 4. Write tests that survive refactoring

**Name the behaviour, not the function.** `returns_empty_list_when_no_orders_match` tells you
what broke from the failure output alone. `test_get_orders_2` tells you to go read it.

**One behaviour per test.** Multiple assertions are fine when they describe one outcome;
multiple *scenarios* in one test hide everything after the first failure.

**Arrange, act, assert — visibly separated.** If arrange is longer than the other two combined,
the code under test needs too much context, which is itself worth reporting.

**Assert against an independent expectation.** The expected value must come from somewhere
other than the code's own logic. Re-deriving it the same way the implementation does produces a
test that passes by construction and can never disagree — the most dangerous kind, because it
looks like coverage.

**Build test data with factories, not shared fixtures.** A fixture mutated by one test bleeds
into the next, and the resulting failures are order-dependent and miserable to find. Each test
should be readable alone.

**Done when:** you could rewrite the implementation entirely and the tests would still be
correct as specifications.

## 5. Testing code that was not built for it

When the code has no tests and you need to change it, do not start by testing what it *should*
do — pin down what it *does*:

1. Write **characterization tests** that assert current behaviour, including behaviour that
   looks wrong. You are building a safety net, not a specification.
2. Refactor under that net until the code is reachable.
3. *Then* fix the behaviour that was wrong, changing the test in the same commit so the change
   is visible in review.

Doing this in the other order means changing behaviour and structure at once, with no way to
tell which broke it.

## 6. Keep the suite trustworthy

- **A flaky test is a failing test.** Quarantine or fix it the day it appears. One tolerated
  flake teaches everyone to re-run red builds, and after that the suite means nothing.
- **Speed is correctness in practice.** A suite too slow to run is a suite not run.
- **Delete tests that no longer earn their place.** Tests for deleted behaviour, duplicates,
  and tests that only assert the mock was called.
- **When a bug escapes, ask which test should have caught it.** That question, answered
  honestly, improves the suite faster than any coverage target.

Versions

RepositoryScoreLicence
This page · OKHP3/skillz90MIT
open-agentic-catalog/open-agentic-catalog100Apache-2.0
gathertown/eng-workflow100MIT
nativescript/nativescript100MIT
reddygopalkrishna/developer-agent-skills100MIT
petrkindlmann/qa-skills100MIT
MARUCIE/openclaw-foundry95MIT
Tyler-R-Kendrick/agent-skills95MIT
kid-sid/codex-spellbook95MIT

Database snapshot: 13.11.2026 · package version 4172b9a94685 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 86unit-test
    Writes isolated unit tests for a named file using Arrange-Act-Assert. Use when user requests unit tests, test coverage, or missing test cases for a file.
  • 100unit-test-engineer
    Designs and writes fast, deterministic unit tests that assert behaviour, cover boundaries and negative cases, and fail when the code is wrong. Use when adding or improving unit tests for existing or new code.
  • 100unit-test-engineer
    Designs and writes fast, deterministic unit tests that assert behaviour, cover boundaries and negative cases, and fail when the code is wrong. Use when adding or improving unit tests for existing or new code.
  • 100write-tests
    Write unit and integration tests. Use when the user says "write tests for this", "add test coverage", "how do I test this", "TDD", "red green refactor", "unit test this function", "test this module", "I need tests for", or has code that lacks tests - even if they don't explicitly say "write tests".
  • 100test-unit
    Write unit and integration tests for a named module or change. Use when "write unit tests" or "add tests for this function". Coverage plan → plan-test-coverage. Mutation score → test-mutation. Browser check → test-playwright.
  • 100writing-unit-tests
    Writes and reviews focused, deterministic unit tests that verify behavior through public interfaces instead of implementation details. Use whenever tests are added to code that already exists, and when the request mentions unit tests, test coverage, edge cases, mocks or test…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.