tdd
БесплатноБез исполняемых скриптовНе проверенGuides building a feature or fixing a bug test-first with the red-green-refactor cycle: agree a list of behaviours, write one failing test, make it pass with…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Test-Driven Development
Overview
Test-driven development is a way of writing code in very short loops: state one behaviour as an automated test, watch it fail, write just enough code to pass, then improve the design while the tests protect you. For an agent the discipline matters more than for a person, because the failing test is evidence that the test can fail at all and the passing run is evidence the change works; neither can be claimed without running something. This skill sets out the loop, what to show the user at each step, and how to apply it to new features, bug fixes and code that has no tests yet.
Instructions
1. Learn how tests run in this project
Before writing anything, find the runner, where tests live, how they are named, and the command for a single test. Read package.json, pyproject.toml, Makefile or the CI workflow; copy the project's own command instead of inventing one. Then run the whole suite once. If it is already failing, tell the user before going further: a red baseline hides whether your new test fails for the right reason.
| Runner | Whole suite | One test by name |
|---|---|---|
| Node.js built-in | node --test |
node --test --test-name-pattern="leftover cents" |
| Vitest | npx vitest run |
npx vitest run -t "leftover cents" |
| Jest | npx jest |
npx jest -t "leftover cents" |
| pytest | pytest -q |
pytest -q -k "31st" or pytest "tests/test_schedule.py::test_december_rolls_over" |
| Go | go test ./... |
go test -run 'TestSplitBill' ./... |
| Cargo | cargo test |
cargo test split_bill |
2. Agree the interface and write a test list
Settle with the user what the caller sees: function or endpoint name, inputs, outputs, errors. Then write a short list of behaviours in plain language, one line each, ordered from the central case outward: main scenario, variations, boundaries, failures. The list is about what the code does for its caller, not how it will be built. Show it to the user; it is the cheapest place to catch a misunderstanding. New cases that occur to you mid-loop are added to the list, not implemented on the spot.
3. Red: one failing test
Turn the top item into one test. Name it as a sentence about behaviour. Arrange, act, assert; one reason to fail. Call the code the way a real caller would, through its public interface. Run it and read the failure:
- It must fail because the behaviour is missing: an assertion mismatch, or at the very start a missing module or function.
- If it fails for another reason (syntax error, wrong import path, broken fixture), fix the test until the failure is the expected one.
- If it passes straight away, do not move on. Either the behaviour already exists (keep the test as a guard and take the next item) or the test cannot fail (prove it can by breaking the code on purpose, then restore it).
4. Green: the least code that passes
Write only what this test demands and run the entire suite, not just the new test. A hard-coded or naive answer is acceptable when the next test will force the general one; do not add branches, parameters or error handling that no test asks for. Never reach green by weakening the test: deleting an assertion, loosening a comparison, or pasting the actual output into the expected value without checking it against the requirement.
5. Refactor: improve the design while green
With every test passing, look at both the production code and the tests: unclear names, duplication, a function doing two jobs, setup repeated across tests. Change one thing, run the suite, repeat. Add no behaviour in this step; if tidying reveals a missing case, put it on the list. Skipping this step is the most common way the practice decays into a pile of passing but tangled code.
6. Repeat, and commit on green
Take the next item. Commit whenever the suite is green and the code is tidy, so any later step can be undone cheaply. Stop when the list is empty, and say so.
7. Bug fixes start with a reproduction
Write a test that fails in the way the bug report describes, at the lowest level that shows the defect. Run it and confirm the failure matches the report. Fix the code, see the test pass, and keep the test. Then ask what neighbouring inputs share the cause and add those cases.
8. Changing code that has no tests
Do not test-drive a change into untested code blind. First write characterization tests: call the existing code with representative inputs and assert whatever it does today, even where that looks odd. They are the baseline. If the code cannot be called from a test because it reaches for a database, the clock or the network, make the smallest change that lets a test supply those (pass them in as parameters), then proceed with the normal loop.
9. What to replace with a test double
Use the real collaborator whenever it is fast and deterministic. Substitute only at the edges of the system: network services, payment and
Установить tdd в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл tdd?
Guides building a feature or fixing a bug test-first with the red-green-refactor cycle: agree a list of behaviours, write one failing test, make it pass with the least code, tidy up while green, repeat. Covers reproducing bugs with a failing test, pinning down untested legacy code before changing it, and choosing what to replace with test doubles. Use when the user says "use TDD", "write the test first", "red-green-refactor", "test-drive this function", "add a regression test before fixing", or asks how to add tests while building.
Как установить скилл tdd?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл tdd запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
от Anthropicinternal-comms
A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
от Anthropicskill-development
This skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…
от Anthropic