test-driven-development
БесплатноБез исполняемых скриптовНе проверенUse when writing production code. Enforces RED-GREEN-REFACTOR cycle: write failing test, make it pass, improve design. Prevents test-after development and…
от MadAppGang★ 290 звёзд на GitHubОб этом скилле
Test-Driven Development (TDD)
Iron Law: "NO PRODUCTION CODE WITHOUT A FAILING TEST FIRST"
When to Use
Use this skill when:
- Writing new functions, methods, or classes
- Adding features to existing code
- Fixing bugs (write test that reproduces bug first)
- Refactoring code (tests verify behavior preservation)
- Implementing API endpoints or business logic
- Creating UI components with testable behavior
Red Flags (Violation Indicators)
Watch for these patterns that indicate TDD violations:
- Implementation First - Writing production code before any test exists ("I'll write the function, then add tests")
- "Tests After" Promise - Planning to write tests later ("Let me implement this quickly, I'll add tests after")
- "Same Purpose" Rationalization - Claiming manual testing is equivalent ("I tested it manually, that's the same thing")
- Skipping "Simple" Code - Avoiding tests for "obvious" logic ("This function is too simple to test")
- Happy Path Only - Writing tests only for success cases, ignoring errors ("The normal case works, that's enough")
- No Test for Changes - Modifying code without adding corresponding test ("Just a small change, doesn't need a test")
- "Just a Small Fix" - Bypassing TDD for "quick fixes" ("It's only one line, I don't need a test")
Violation Detection: If you find yourself saying "I'll test this after I get it working," you're violating TDD.
RED-GREEN-REFACTOR Cycle
TDD follows a strict 3-phase workflow:
Phase 1: RED (Write a Failing Test)
Objective: Specify desired behavior through a test that fails
Steps:
- Write the test first - Before any production code exists
- Define expected behavior - What should the code do?
- Use API you wish existed - Test the interface you want
- Run the test - Verify it fails (if it passes, you didn't test new behavior)
- Check failure reason - Ensure it fails for the right reason (missing code, not syntax error)
Example (TypeScript/Jest):
// tests/user-validator.test.ts
describe('UserValidator', () => {
it('rejects email without @ symbol', () => {
const validator = new UserValidator();
const result = validator.validateEmail('invalid-email');
expect(result.isValid).toBe(false);
expect(result.error).toBe('Email must contain @ symbol');
});
});
// Run: npm test
// Result: FAIL - UserValidator is not defined ✓ (correct failure)
Red Phase Complete When: Test fails with expected error message
Phase 2: GREEN (Make the Test Pass)
Objective: Write minimal code to make test pass
Steps:
- Write minimal code - Just enough to pass the test
- Don't optimize yet - Resist the urge to add "nice-to-have" features
- Run the test - Verify it passes
- Commit frequently - Small, passing test = commit point
Example (TypeScript):
// src/user-validator.ts
interface ValidationResult {
isValid: boolean;
error?: string;
}
export class UserValidator {
validateEmail(email: string): ValidationResult {
if (!email.includes('@')) {
return { isValid: false, error: 'Email must contain @ symbol' };
}
return { isValid: true };
}
}
// Run: npm test
// Result: PASS ✓
Green Phase Complete When: Test passes consistently
Phase 3: REFACTOR (Improve Design)
Objective: Improve code quality while keeping tests green
Steps:
- Look for duplication - Extract repeated code
- Improve naming - Make intent clearer
- Simplify logic - Reduce complexity
- Run tests after each change - Ensure behavior preserved
- Commit when satisfied - Refactored code + passing tests = commit
Example (TypeScript - Refactored):
// src/user-validator.ts
interface ValidationResult {
isValid: boolean;
error?: string;
}
export class UserValidator {
private static readonly EMAIL_REQUIRED_CHARS = '@';
private static readonly EMAIL_ERROR = 'Email must contain @ symbol';
validateEmail(email: string): ValidationResult {
if (!this.containsRequiredChars(email)) {
return this.createError(UserValidator.EMAIL_ERROR);
}
return this.createSuccess();
}
private containsRequiredChars(email: string): boolean {
return email.includes(UserValidator.EMAIL_REQUIRED_CHARS);
}
private createError(message: string): ValidationResult {
return { isValid: false, error: message };
}
private createSuccess(): ValidationResult {
return { isValid: true };
}
}
// Run: npm test
// Result: PASS ✓ (behavior unchanged)
Refactor Phase Complete When: Code is clean AND tests still pass
Anti-patterns Table
| Anti-pattern | ✗ Wrong Approach | ✓ Correct TDD Approach |
|---|---|---|
| Test-After | Write calculateTotal() function, then write tests |
Write test for calculateTotal(), see it fail, implement function |
Установить test-driven-development в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл test-driven-development?
Use when writing production code. Enforces RED-GREEN-REFACTOR cycle: write failing test, make it pass, improve design. Prevents test-after development and ensures verified behavior.
Как установить скилл 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