Skip to content
Skills Library
Programming · Testing

clean-tests

/clean-tests

Test craft — fast, independent, deterministic tests that assert one concept, cover boundary conditions, and never hide a failure (T1-T9, FIRST). Use when writing or refactoring tests, and on slow or flaky tests, skipped or `.only` tests, happy-path-only coverage, or tests coupled to implementation detail.

Licence
MIT
Last repository change
11.11.2026

Assessment and security

100/ 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.
Content35 / 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
1
Deprecation

No signals detected. Repository changed on 11.11.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

Test craft — fast, independent, deterministic tests that assert one concept, cover boundary conditions, and never hide a failure (T1-T9, FIRST). Use when writing or refactoring tests, and on slow or flaky tests, skipped or `.only` tests, happy-path-only coverage, or tests coupled to implementation detail.

Original author description

Test craft — fast, independent, deterministic tests that assert one concept, cover boundary conditions, and never hide a failure (T1-T9, FIRST). Use when writing or refactoring tests, and on slow or flaky tests, skipped or `.only` tests, happy-path-only coverage, or tests coupled to implementation detail.

How it works

  1. The property that matters
  2. FIRST
  3. T5 — Boundary conditions are where bugs live
  4. T6 — Exhaustively test around a bug
  5. One concept per test
  6. Arrange, act, assert
  7. Mock at the boundary, never the subject
  8. T9 — Fast, and never live
  9. T4 / T7 — Never hide a failure
  10. T8 — Hard to test means badly designed
Original SKILL.md headings · 113 lines, 1,034 words
SKILL.md preview
---
name: clean-tests
description: Test craft — fast, independent, deterministic tests that assert one concept, cover boundary conditions, and never hide a failure (T1-T9, FIRST). Use when writing or refactoring tests, and on slow or flaky tests, skipped or `.only` tests, happy-path-only coverage, or tests coupled to implementation detail.
---

# Clean tests

This skill is about **how to write a test well**. Whether a given thing deserves a test at all is decided by `risk-based-testing`, which takes precedence — it exists so that "test everything that could break" does not become "test everything".

A test is production code. It is read more often than the code it covers, and a bad one costs more than no test.

## The property that matters

**A test should fail for exactly one real reason, and that reason should be a behaviour someone cares about.**

Two failure modes to design against:

- **Fails when nothing broke** — coupled to markup, structure, call order, timing or internals. This is the test that gets deleted in frustration during a refactor, taking its real coverage with it.
- **Passes when something broke** — asserts something trivially true, mocks the thing under test, or never reaches the branch it claims to cover.

## FIRST

- **Fast** — milliseconds. A suite nobody waits for is a suite nobody runs.
- **Independent** — no shared mutable state, no ordering dependency. Each test sets up what it needs and can run alone or in any order.
- **Repeatable** — same result on any machine, any time of day, any locale, any timezone. Freeze the clock, seed the randomness, fix the locale.
- **Self-validating** — passes or fails. Never "check the log output".
- **Timely** — written with the code, not bolted on afterwards. For a bug fix, written *before* (`debugging`).

## T5 — Boundary conditions are where bugs live

The happy path is the case you already thought about. Cover instead: empty, one, many, maximum; zero and negative; null, undefined and missing versus present-but-empty; first and last; duplicates; out of order; concurrent; expired; unauthorised.

```ts
it("returns zero for an empty basket", …)
it("applies the discount at exactly the threshold", …)
it("rejects a quantity of -1", …)
```

Off-by-one and empty-input cases justify their own tests more often than any other category.

## T6 — Exhaustively test around a bug

Bugs cluster. When you fix one, test its neighbours: the adjacent branch, the boundary either side, the same mechanism on the sibling path. The cost is minutes; the hit rate is high.

## One concept per test

Not one assertion — one *concept*. Several assertions about the same outcome are fine; assertions about four unrelated behaviours in one test tell you nothing about which broke.

```ts
// Bad — one failure hides the other three
it("user", () => {
  expect(user.name).toBe("Alice")
  expect(user.isValid()).toBe(true)
  user.activate()
  expect(user.isActive).toBe(true)
})

// Good — each names its own behaviour
it("is valid when created with a name and email", …)
it("becomes active when activated", …)
```

The test name should state the behaviour, so a failure in CI is diagnostic on its own. `it("works")` is worthless; `it("rejects a quote whose brand belongs to another tenant")` is a specification.

## Arrange, act, assert

Keep the three visibly separate, and keep the arrangement small. If setup dwarfs the assertion, that is a design signal (`T8`) — the unit under test probably has too many dependencies.

Use builders or factories with sensible defaults so each test states **only what matters to it**. A test that sets twelve fields to assert one of them buries its own point.

## Mock at the boundary, never the subject

Stub what you do not own and cannot control — network, clock, filesystem, randomness, third-party services. Do not mock the thing you are testing, and do not assert on how many times an internal helper was called; assert on the outcome.

Over-mocked tests pass while the system is broken, because they only ever test the mocks.

## T9 — Fast, and never live

No real database, no real HTTP, no real queue, no `sleep`. Use the project's existing fakes and in-memory substitutes. If a test needs a live service, it is an integration test and belongs wherever the project puts those — not in the unit suite.

Wait for conditions, never for durations. A `setTimeout` in a test is a future flake.

## T4 / T7 — Never hide a failure

- A skipped test is an unanswered question. Fix it or delete it; do not leave it skipped with "flaky, fix later".
- A committed `.only` silently disables the rest of the file. Never commit one.
- Flakiness is a bug report about the code or the test — race, shared state, time dependence, ordering. Investigate it; do not add a retry.
- When several tests fail together, read the pattern before fixing them individually. A cluster usually names one cause — often shared state that is not being reset between tests.

Never weaken a test to make a run pass: no widened tolerances, no deleted assertions, no snapshot substituted for a real check (`risk-based-testing`).

## T8 — Hard to test means badly designed

If you need extensive mocking, global state, or access to privates, the design is telling you something. Prefer fixing the seam — inject the dependency, extract the pure logic, separate the decision from the side effect — over contorting the test.

## T2 — Coverage is a diagnostic, not a target

Use it to find paths nobody thought about. Never to justify a test, and never as a number to hit. High coverage with weak assertions is worse than honest gaps, because it buys false confidence.

## Checklist

- [ ] Does the name state the behaviour?
- [ ] Can it fail for exactly one real reason?
- [ ] Would it survive a refactor that preserves behaviour?
- [ ] Would it fail if the behaviour broke? (Check by breaking it.)
- [ ] Independent of order and of other tests' state?
- [ ] Deterministic — clock, randomness, locale, timezone all pinned?
- [ ] Boundary cases covered, not just the happy path? (T5)
- [ ] One concept, with arrange/act/assert visible?
- [ ] Mocks only at boundaries, never the subject?
- [ ] Milliseconds, and no live services? (T9)
- [ ] No skipped tests, no `.only`, no retries hiding a race? (T4)

---

Derived from [clean-code-skills](https://github.com/ertugrul-dmr/clean-code-skills#clean-code-skills-for-ai-agents) (MIT), adapted to be language-neutral. Full catalogue and sync record: `clean-code`. To re-sync: `clean-code-update`.

Versions

The database has no other skills named clean-tests.

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

Downloads in the last 30 days: 2 · ranking

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

Similar skills

  • 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.
  • 100coverage-gaps
    Scan a repository's tests and draw one diagram: which code the tests miss, which kinds of test are absent, which tests assert nothing, and which tests disagree with themselves. Use for /gtest, /testsweep, /sweep, and whenever the user writes or changes a test, asks "is this…
  • 100writing-tests
    Write deterministic tests that fail for real product defects. Use when adding tests, fixing flakes, or reviewing test coverage and reliability.
  • 100test-strategy
    Decides what to test and at which level, then writes fast, deterministic tests that check behavior rather than implementation details. Use when planning how a feature or system should be tested, choosing between unit, integration, contract and end-to-end tests, deciding what to…
  • 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.