에이전트 기반 TDD
에이전트중급
전통적인 TDD는 Red-Green-Refactor를 따릅니다. 이 패턴은 두 개의 Claude Code 에이전트로 이를 자동화합니다: 에이전트 A가 스펙 기반의 실패하는 테스트를 작성하면, 에이전트 B가 통과시키기 위한 최소한의 코드를 구현합니다. 이 사이클은 각 요구사항마다 반복됩니다. 선택적으로 세 번째 에이전트가 리팩토링 단계를 처리합니다. 엄격한 TDD 원칙을 강제하고 설계 단계부터 잘 테스트된 코드를 생산합니다.
TDD테스팅에이전트red-green-refactor
패턴 코드
# TDD Agent Pattern
## CLAUDE.md — Test Writer Agent
```markdown
# Role: Test Writer
You write ONLY test files. Never write implementation code.
## Rules
- Read the spec/requirement first
- Write one test at a time (smallest meaningful assertion)
- Use descriptive test names: "should [expected behavior] when [condition]"
- Import from the implementation file even though it doesn't exist yet
- After writing a test, run it to confirm it FAILS (red phase)
- Mark test with // SPEC: [requirement-id] for traceability
## Test Style
- Framework: Vitest
- Pattern: Arrange-Act-Assert
- Mocking: vi.mock() for external deps only
```
## CLAUDE.md — Implementer Agent
```markdown
# Role: Implementer
You write ONLY implementation code. Never modify test files.
## Rules
- Read the failing test first
- Write the MINIMUM code to make the test pass
- Do not add functionality beyond what the test requires
- Run the test after each change to confirm it PASSES (green phase)
- Do not optimize or refactor — that's a separate phase
## Implementation Style
- Follow existing patterns in the codebase
- Export only what the test imports
- Prefer pure functions where possible
```
## Orchestration
```bash
#!/bin/bash
# tdd-cycle.sh — automated TDD loop
SPEC_FILE=$1
REQUIREMENTS=$(claude -p "Extract requirement IDs from $SPEC_FILE as JSON array")
for REQ in $(echo $REQUIREMENTS | jq -r '.[]'); do
echo "=== Requirement: $REQ ==="
# Red: Write failing test
claude -p "Write a failing test for requirement $REQ from $SPEC_FILE.
Follow Test Writer rules in CLAUDE.md."
# Green: Implement to pass
claude -p "Read the failing test for $REQ. Write minimum code
to make it pass. Follow Implementer rules in CLAUDE.md."
# Verify
npx vitest run --reporter=verbose
done
# Refactor phase (optional)
claude -p "Review all implementation files. Refactor for clarity
without changing behavior. All tests must still pass."
```
이 패턴을 프로젝트 설정에 복사하여 적용하세요.
실행 미리보기
에이전트 기반 TDD
에이전트 기반 TDD에 대해
Claude Code 패턴은 복잡한 개발 시나리오를 효과적으로 다루기 위한 검증된 아키텍처 설계와 워크플로우 구조입니다. 에이전트 기반 TDD은(는) 중급 수준의 에이전트 패턴으로, 프로젝트에 맞게 응용할 수 있는 테스트된 반복 가능한 접근 방식을 제공하여 더 효율적이고 일관된 결과를 만들어 냅니다.