TDD of what is necessary: when a change needs a failing test first and when it needs none, RED/GREEN/REFACTOR, the [tdd-gate] block, lowest-level tests, affected-first runs, determinism, flakes. Invoke when starting any feature, bug fix or behavioural refactor, or when a project has no test runner yet.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Aval Tdd?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/alvaroofernaandez-aval-tdd)
---
name: aval-tdd
description: >
TDD of what is necessary: when a change needs a failing test first and when it
needs none, RED/GREEN/REFACTOR, the [tdd-gate] block, lowest-level tests,
affected-first runs, determinism, flakes. Invoke when starting any feature,
bug fix or behavioural refactor, or when a project has no test runner yet.
---
## The rule
A test is written first wherever a change adds or alters behaviour that can be
wrong. Nowhere else. A test that cannot catch a real regression is cost with no
return: it slows every run and breaks on every rewording.
### A failing test comes first (RED, then GREEN, then refactor)
- **Logic:** a branch, loop, parser, mapping, validation, calculation, state
transition, retry, concurrency.
- **Risk:** money, security, permissions, data written to disk or a database,
anything a person cannot undo.
- **A bug fix:** the RED test reproduces the bug before the fix.
- **A behavioural refactor:** if nothing pins the current behaviour, a
characterisation test pins it first.
- **Shared code:** for every existing command or option that shares the code you
touched, one regression test proves its previous behaviour holds.
### No new test is needed
- Copy, labels and messages: the one place that pins user-facing text changes,
nothing else.
- Configuration values, dependency bumps, renames, moves, formatting.
- Wiring with no decision in it: the entry point's smoke test already covers it.
- Deleting dead code: the existing suite is the check.
- Docs and comments.
When you skip a test, say so in one line of your report, with the reason. If you
cannot tell whether a change has logic, it has: write the test.
### Iron law, where a test is required
1. **RED:** the test fails on its assertion, not on an import, compile or setup
error.
2. **GREEN:** the minimum code that passes. Nothing speculative.
3. **REFACTOR:** clean up while green.
Never write the implementation first and cover it afterwards: that skips the
design feedback and tests the code you already trust. If you catch yourself
doing it, delete the implementation and restart from RED.
### Pre-flight (emit before implementation code)
```
[tdd-gate]
Runner: <go test | vitest | pytest | …>
RED test: <path::name — what it asserts and why it fails now>
```
or, for a change in the "no new test" list:
```
[tdd-gate]
No test: <which case above, in one line>
```
If you cannot fill either honestly, do not write implementation code yet.
### Setup first
A project with no runner gets one before the first change that needs a test: the
runner, its config and one passing smoke test, in their own commit.
## How to write the test
### Lowest level that catches the regression
Assert through the public interface (output, exit code, return value, data
written), never private helpers or internal order.
| What you verify | Level |
| --- | --- |
| A parser, planner, mapping, renderer | Unit, in memory, scratch in the framework's temp dir |
| A command or handler's behaviour | In process: call the entry function with args, streams and env |
| A schema, protocol or file format | One contract test, parameterised, in one place |
| Process startup: argv, exit code, PATH | One real-process smoke test per entry point |
| Repository rules: budgets, boundaries, docs | A repo-level guard test |
| Real browsers, terminals, services | e2e behind a tag, out of the default run |
If a command cannot be tested in process, that is a design finding: make its
entry point take args, streams and env instead of reading globals.
### What to assert
| Do | Avoid |
| --- | --- |
| Error identity, returned data, state, persisted invariants | Message text in logic tests |
| One reason to fail per test | Private names, internal order, counts of temp files |
| A parameterised table in one file | The same invariant re-checked across many files |
| In-memory fakes that behave like the real thing | Mocks that assert call order |
- Errors: Go `errors.Is` / `errors.As`; TS/JS `instanceof` or an error `code`;
Python `pytest.raises(SpecificError)`. If the code returns only a string, add a
sentinel, class or code first (RED), then assert it.
- User-facing text is pinned in one place, so rewording breaks one test, not forty.
- Evidence before abstractions: add an interface or seam only when a test (or a
second real implementation) uses it today. "Easier to mock later" is not a need.
### Determinism
- No fixed sleeps. Inject a clock, or poll a condition with a deadline and fail
with the last observed state.
- Scratch only in the framework's temp dir (`t.TempDir()`, `tmp_path`, a cleaned
`mkdtemp`). Never the repo, `$HOME` or a fixed `/tmp` name. Env through the
framework's scoped helper (`t.Setenv`, `monkeypatch`, `vi.stubEnv`).
- Goldens are regenerated by a flag, never by hand; mask times, paths and versions.
- Committed tests never read git history or a fixed commit.
## Running
- While iterating: only the focused test.
- Before committing: the tests affected by the change. In Go, the touched
packages and their importers; elsewhere, the import graph (for example
`archsieve affected`). Fall back to the full suite when a manifest, lockfile,
test helper, fixture or build config changed.
- Once at the end (and in CI): the full suite. Do not rerun it to "check again".
- Mutation testing is on demand over touched code when a test looks weak; a
surviving mutant becomes a RED test. Never a gate.
### Flake protocol
1. Reproduce by repetition: `go test -race -count=20 -run '^TestX$'`,
`vitest --repeat 20`, `pytest --count=20 -k x`.
2. Run it alone and serially, then with its package. Passing alone and failing in
parallel is a finding (shared env, ports, files, globals), not noise.
3. Find the mechanism. It is often a real race: make it deterministic (hold an
event back, a fake that answers late) to get a RED that fails every run, then
fix the code.
4. Never loosen an assertion, add a sleep or retry blindly until it passes.
### Differential check
Before finishing a change to a command, build the base commit in a separate
worktree, run both builds with the same args and throwaway home, and compare
stdout, stderr and exit code. Every difference you did not intend is a
regression: fix it and pin it with a test.
## Output contract
- **What ran:** the exact command, exit code, pass, fail and skip counts.
- **What did not run, and why:** a tag not set, a missing tool, another OS.
Skipped is not passed.
- **Failures:** the test name and the output tail, not a paraphrase.
- **TDD evidence:** the RED line and the GREEN output per rule, the tests skipped
with their reason, and the differential result.