red-green-refactor
БесплатноБез исполняемых скриптовНе проверенUse before changing code to fix a bug or add behavior, in any language, even when the user just says "fix it" or pastes a one-line function: reproduce the…
от testland★ 18 звёзд на GitHubОб этом скилле
red-green-refactor
Overview
Test-driven development (TDD) writes the test before the code, one small behavior at a time. Martin Fowler's short form of the loop (fowler-tdd):
- "Write a test for the next bit of functionality you want to add."
- "Write the functional code until the test passes."
- "Refactor both new and old code to make it well structured."
Kent Beck's Canon TDD adds the step most people skip: start from a written list of test scenarios and turn "exactly one item on the list into an actual, concrete, runnable test" at a time.
For a coding agent, the loop is also the proof that a change works. Anthropic's Claude Code best practices put it as "Give Claude a check it can run" and "Have Claude show evidence rather than asserting success: the test output". A test that was seen failing and then seen passing is that evidence. A test written after the code and only ever seen passing is not: it may pass for the wrong reason.
When to use
- Adding a function, endpoint, rule or option that has observable behavior.
- Fixing a bug: reproduce it as a failing test first (Step 6).
- Changing code that other code depends on, where "it still works" needs proof.
- Any time you are about to write "done", "fixed" or "this should work".
Not a fit: throwaway spikes (delete them, then test-drive the real code), pure layout or styling (use a visual check), or a project with no way to run tests yet. In that last case, set up the runner first and say so; don't skip the loop silently.
Neighbors: test-case-ideation-from-story (qa-process) and
boundary-value-generator (qa-test-data) help fill the test list in
Step 2; the per-language unit-test skills (python-unit-tests,
js-unit-tests, jvm-unit-tests, go-unit-tests, dotnet-unit-tests)
cover the frameworks themselves; test-code-conventions (qa-test-review) reviews
finished tests. This skill owns the order of work and the evidence.
Step 1 - Find the test command and run the suite once
Before changing anything, find how this project runs tests (README,
package.json scripts, pyproject.toml, Makefile, CI workflow) and
run the existing suite. Write down the result.
This baseline matters later: if three tests were already red before you started, they are not yours, and you must not "fix" them by editing them to pass. Say they were red at the start.
Commands to run one test, which the loop below uses constantly:
| Stack | Run one file or test | Source |
|---|---|---|
| pytest | pytest tests/test_mod.py::test_func |
pytest usage |
| Vitest | npx vitest run foobar -t "name pattern" |
vitest cli |
| Jest | npx jest path/to/my-test.js -t "name pattern" |
jest cli |
| Go | go test ./pkg/... -run 'TestParse$' -count=1 |
go help testflag; go test |
| Maven Surefire | mvn -Dtest=TestCircle#mytest test |
surefire single test |
| Gradle | ./gradlew test --tests SomeTestClass.someSpecificMethod |
gradle testing |
| .NET | dotnet test --filter "FullyQualifiedName~MyTestsClass" |
dotnet filter |
| Rust | cargo test name_filter |
cargo test |
Per go test, "The idiomatic way to disable test caching explicitly is to use -count=1", which matters when you need to see a test actually run red.
Step 2 - Write the test list
Per Canon TDD, step 1 is "Write a list of the test scenarios you want to cover". Write it in plain words, in your reply or a scratch note, before any test code:
parse_duration
- [ ] "90s" -> 90 seconds
- [ ] "1h30m" -> 5400 seconds (units combine)
- [ ] "" -> ValueError
- [ ] "5x" (unknown unit) -> ValueError naming the unit
- [ ] "-5m" -> ValueError (negative not allowed per spec)
Include the error cases and edges the request implies, not only the happy path. Do not turn the whole list into test code now: Canon TDD calls converting "all the items on the Test List into concrete tests" up front a mistake, because the first passing test usually changes what the rest should look like.
Step 3 - Red: one test, run it, read the failure
Turn exactly one item into a test. Run only that test (Step 1 table) and read the output before writin
Установить red-green-refactor в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл red-green-refactor?
Use before changing code to fix a bug or add behavior, in any language, even when the user just says "fix it" or pastes a one-line function: reproduce the problem with a failing test first, watch it fail for the right reason, make the smallest change that passes, refactor, and show the test output before saying it is fixed or works.
Как установить скилл red-green-refactor?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл red-green-refactor запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic