tdd-workflow
БесплатноБез исполняемых скриптовНе проверенTest-Driven Development guidance. Use when writing code, implementing features, or fixing bugs in projects that follow TDD methodology. Provides the…
Об этом скилле
TDD Workflow Skill
This skill provides guidance for Test-Driven Development methodology.
The Core Cycle
┌─────────────────────────────────────────────────┐
│ │
│ ┌───────┐ ┌───────┐ ┌──────────┐ │
│ │ RED │ ──▶ │ GREEN │ ──▶ │ REFACTOR │ │
│ └───────┘ └───────┘ └──────────┘ │
│ │ │ │
│ └─────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────┘
Phase 1: RED - Write a Failing Test
Purpose
Define the expected behavior BEFORE writing implementation.
Actions
- Create or open test file
- Write a test that describes ONE behavior
- Run the test
- Verify it FAILS (important!)
Example (TypeScript/Jest)
describe('UserService', () => {
describe('createUser', () => {
it('should create a user with valid email', async () => {
const user = await userService.createUser({
email: '[email protected]',
name: 'Test User'
});
expect(user.id).toBeDefined();
expect(user.email).toBe('[email protected]');
});
it('should throw error for invalid email', async () => {
await expect(
userService.createUser({ email: 'invalid', name: 'Test' })
).rejects.toThrow('Invalid email format');
});
});
});
Common Mistakes
- Writing tests that pass immediately (means the test is wrong)
- Testing implementation details instead of behavior
- Writing too many tests before any implementation
Phase 2: GREEN - Make It Pass
Purpose
Write the MINIMUM code to make the test pass.
Actions
- Implement just enough to pass the failing test
- No extra features
- No optimization
- Run tests to verify PASS
Example
// MINIMUM implementation to pass the tests above
class UserService {
async createUser(data: { email: string; name: string }) {
if (!data.email.includes('@')) {
throw new Error('Invalid email format');
}
return {
id: crypto.randomUUID(),
email: data.email,
name: data.name
};
}
}
Common Mistakes
- Over-engineering on first pass
- Adding features not covered by tests
- "While I'm here" additions
Phase 3: REFACTOR - Improve Quality
Purpose
Clean up the code while keeping tests green.
Actions
- Look for improvements:
- Duplication
- Poor naming
- Complex logic
- Long functions
- Make ONE change
- Run tests
- If green, continue. If red, undo.
Example
// REFACTORED version
const EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
class UserService {
async createUser(data: CreateUserInput): Promise<User> {
this.validateEmail(data.email);
return this.buildUser(data);
}
private validateEmail(email: string): void {
if (!EMAIL_REGEX.test(email)) {
throw new InvalidEmailError(email);
}
}
private buildUser(data: CreateUserInput): User {
return {
id: crypto.randomUUID(),
...data,
createdAt: new Date()
};
}
}
Refactoring Checklist
- Extract long methods
- Rename unclear variables/functions
- Remove duplication (DRY)
- Simplify conditionals
- Add type safety
Test Patterns
Arrange-Act-Assert (AAA)
it('should calculate discount correctly', () => {
// Arrange
const cart = new Cart();
cart.addItem({ price: 100 });
// Act
const discount = cart.calculateDiscount();
// Assert
expect(discount).toBe(10);
});
Given-When-Then (BDD)
describe('given a cart with items over $100', () => {
describe('when calculating discount', () => {
it('then should apply 10% discount', () => {
// ...
});
});
});
Coverage Commands
JavaScript/TypeScript
# Jest
npx jest --coverage
# Vitest
npx vitest run --coverage
Python
pytest --cov=src --cov-report=html
Go
go test -cover ./...
go test -coverprofile=coverage.out ./...
Anti-Patterns
1. Test After
Writing code first, tests second defeats the purpose.
2. Testing Implementation
// BAD: Testing HOW it works
expect(service.internalMethod).toHaveBeenCalled();
// GOOD: Testing WHAT it does
expect(result).toEqual(expectedOutput);
3. Brittle Tests
// BAD: Breaks if order changes
expect(users[0].name).toBe('Alice');
// GOOD: Resilient assertion
expect(users).toContainEqual(expect.objectContaining({ name: 'Alice' }));
4. No Refactoring
Skipping refactor phase leads to technical debt.
Quick Reference
| Phase | Question to Answer | Action |
|---|---|---|
| RED | What should it do? | Write failing test |
| GREEN | Does it work? | Write minimal code |
| REFACTOR | Is it clean? | Improve structure |
Integration
This skill works with:
- conductor-context:
Установить tdd-workflow в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл tdd-workflow?
Test-Driven Development guidance. Use when writing code, implementing features, or fixing bugs in projects that follow TDD methodology. Provides the Red-Green-Refactor cycle structure.
Как установить скилл tdd-workflow?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл tdd-workflow запускает скрипты?
Нет, скилл состоит только из инструкций (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