test-driven-development
БесплатноБез исполняемых скриптовНе проверенUse when implementing features or fixing bugs - enforces RED-GREEN-REFACTOR cycle requiring tests to fail before writing code
Об этом скилле
Violating the letter of the rules is violating the spirit of the rules.
| Phase | Action | Command Example | Expected Result |
|---|---|---|---|
| RED | Write failing test | cargo test test_name |
FAIL (feature missing) |
| Verify RED | Confirm correct failure | Check error message | "function not found" or assertion fails |
| GREEN | Write minimal code | Implement feature | Test passes |
| Verify GREEN | All tests pass | cargo test |
All green, no warnings |
| REFACTOR | Clean up code | Improve while green | Tests still pass |
Iron Law: NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST
Ask your human partner for exceptions:
- Throwaway prototypes (will be deleted)
- Generated code
- Configuration files
Thinking "skip TDD just this once"? Stop. That's rationalization.
1. RED - Write Failing Test
Write one minimal test showing what should happen.
Requirements:
- Test one behavior only ("and" in name? Split it)
- Clear name describing behavior
- Use real code (no mocks unless unavoidable)
See resources/language-examples.md for Rust, Swift, TypeScript examples.
2. Verify RED - Watch It Fail
MANDATORY. Never skip.
Run the test and confirm:
- ✓ Test fails (not errors with syntax issues)
- ✓ Failure message is expected ("function not found" or assertion fails)
- ✓ Fails because feature missing (not typos)
If test passes: You're testing existing behavior. Fix the test. If test errors: Fix syntax error, re-run until it fails correctly.
3. GREEN - Write Minimal Code
Write simplest code to pass the test. Nothing more.
Key principle: Don't add features the test doesn't require. Don't refactor other code. Don't "improve" beyond the test.
4. Verify GREEN - Watch It Pass
MANDATORY.
Run tests and confirm:
- ✓ New test passes
- ✓ All other tests still pass
- ✓ No errors or warnings
If test fails: Fix code, not test. If other tests fail: Fix now before proceeding.
5. REFACTOR - Clean Up
Only after green:
- Remove duplication
- Improve names
- Extract helpers
Keep tests green. Don't add behavior.
6. Repeat
Next failing test for next feature.
// Code written FIRST
def validate_email(email):
return "@" in email # Bug: accepts "@@"// Test written AFTER
def test_validate_email():
assert validate_email("[email protected]") # Passes immediately!
// Missing edge case: assert not validate_email("@@")
Tests written after verify remembered cases, not required behavior.
- RED - Write test first (including edge case):
def test_validate_email():
assert validate_email("[email protected]") # Will fail - function doesn't exist
assert not validate_email("@@") # Edge case up front
- Verify RED - Run test, watch it fail:
NameError: function 'validate_email' is not defined
- GREEN - Implement to pass both cases:
def validate_email(email):
return "@" in email and email.count("@") == 1
- Verify GREEN - Both assertions pass, bug prevented.
Result: Test failed first, proving it works. Edge case discovered during test writing, not in production.
// 200 lines of untested code exists
// Developer thinks: "I'll keep this and write tests that match it"
// Or: "I'll use it as reference to speed up TDD"
Result: All the problems of test-after, none of the benefits of TDD.
git stash # Or delete the file
Then start TDD:
- Write first failing test from requirements (not from code)
- Watch it fail
- Implement fresh (might be diff
Установить test-driven-development в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл test-driven-development?
Use when implementing features or fixing bugs - enforces RED-GREEN-REFACTOR cycle requiring tests to fail before writing code
Как установить скилл test-driven-development?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл test-driven-development запускает скрипты?
Нет, скилл состоит только из инструкций (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