CClaude Code Catalog
全パターン

エージェントベース TDD

エージェント中級

従来のTDDはRed-Green-Refactorに従います。このパターンは2つのClaude Codeエージェントでこれを自動化します:エージェントAが仕様に基づいた失敗するテストを書き、エージェントBが通過させるための最小限のコードを実装します。このサイクルは各要件ごとに繰り返されます。オプションで3番目のエージェントがリファクタリングフェーズを担当します。厳格な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は中級レベルのエージェントパターンで、プロジェクトに合わせて応用できるテスト済みの再現可能なアプローチを提供し、より効率的で一貫した成果を実現します。

関連パターン