practicing-tdd

Guide Test-Driven Development workflow with Red-Green-Refactor cycle. Use when developing features, fixing bugs, or when user mentions TDD/テスト駆動開発/test-first.

⭐2stars🔀0forks📁View on GitHub🕐Updated Nov 4, 2025⬇️1downloads

When & Why to Use This Skill

This Claude skill facilitates a professional Test-Driven Development (TDD) workflow by guiding developers through the essential Red-Green-Refactor cycle. It ensures high-quality software engineering by enforcing a test-first methodology, managing task-specific ToDo lists, and maintaining strict quality gates such as 80% code coverage and automated linting checks.

Use Cases

  • New Feature Implementation: Systematically building new functionality by defining requirements through failing tests before writing the minimum necessary production code.
  • Reliable Bug Fixing: Resolving software defects by first creating a reproduction test case to confirm the issue, then implementing a fix that passes the test and prevents future regressions.
  • Safe Code Refactoring: Improving internal code structure and readability with the confidence of a comprehensive test suite to ensure no functional regressions are introduced.
  • Continuous Quality Maintenance: Enforcing project standards by automatically running test suites, checking type safety, and monitoring code coverage thresholds during the development process.
namePracticing TDD
descriptionGuide Test-Driven Development workflow with Red-Green-Refactor cycle. Use when developing features, fixing bugs, or when user mentions TDD/テスト駆動開発/test-first.
allowed-toolsRead, Write, Edit, Bash

Practicing TDD

テスト駆動開発(TDD)のベストプラクティスに従った開発フローを管理するスキル。

いつ使うか

  • プロジェクト(プロダクト、アプリ、サイト等)の開発時
  • 新機能実装時
  • バグ修正時
  • ユーザーがTDD、テスト駆動開発について言及した時

基本原則

Red-Green-Refactor サイクル

1. Red    → テストを書いて失敗させる
2. Green  → テストを通す最小限のコード
3. Refactor → コードを整理整頓
4. 繰り返し

開発手順

ステップ1: ToDo リスト作成

やるべきことを箇条書きで整理(テストリスト)

ステップ2: Red(レッド)

  1. ToDo リストから1つピックアップ
  2. テストから書く(テストファースト)
  3. テストを実行して失敗させる

ステップ3: Green(グリーン)

  1. 失敗しているテストを成功させることに集中
  2. 最小限のコードを書く(綺麗より動作優先)
  3. 全てのテストが成功することを確認

ステップ4: Refactor(リファクタリング)

  1. 全てのテストが成功している状態で整理整頓
  2. テストは通ったままにする
  3. 実装コード、テストコード両方をリファクタリング

ステップ5: 繰り返し

  1. 気付きを ToDo リストに反映
  2. 次の ToDo を選んで Red に戻る

品質基準

テスト配置

  • テストコードは src/__tests__/ または実装ファイルと同階層の *.test.ts(x) に配置
  • pnpm test で必ず全スイートを実行

カバレッジ基準

  • コードカバレッジは常に 80% 以上 を維持
  • CI で閾値を下回った場合はジョブを fail させる

バグ修正フロー

  1. 再現テスト(Red)を書く
  2. 修正(Green)
  3. リファクタリング(Refactor)

品質ゲート

テスト追加・変更後は必ず実行:

pnpm run lint && pnpm run typecheck

参考記事

詳細は references.md を参照。

注意事項

  • テストを書かずに実装を進めない
  • 複数の機能を同時に実装しない(1つずつ)
  • テストが失敗したままリファクタリングしない
  • カバレッジ80%未満でコミットしない