jpskill.com
💼 ビジネス コミュニティ

tdd-guide

??ニットテストの作成、テストフィクスチャやモックの生成、カバレッジの分析、TDDワークフローのガイドを通じて、テストコードの作成と改善を支援するSkillです。

📜 元の英語説明(参考)

Test-driven development skill for writing unit tests, generating test fixtures and mocks, analyzing coverage gaps, and guiding red-green-refactor workflows across Jest, Pytest, JUnit, Vitest, and Mocha. Use when the user asks to write tests, improve test coverage, practice TDD, generate mocks or stubs, or mentions testing frameworks like Jest, pytest, or JUnit. Handles test generation from source code, coverage report parsing (LCOV/JSON/XML), quality scoring, and framework conversion for TypeScript, JavaScript, Python, and Java projects.

🇯🇵 日本人クリエイター向け解説

一言でいうと

??ニットテストの作成、テストフィクスチャやモックの生成、カバレッジの分析、TDDワークフローのガイドを通じて、テストコードの作成と改善を支援するSkillです。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o tdd-guide.zip https://jpskill.com/download/5465.zip && unzip -o tdd-guide.zip && rm tdd-guide.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/5465.zip -OutFile "$d\tdd-guide.zip"; Expand-Archive "$d\tdd-guide.zip" -DestinationPath $d -Force; ri "$d\tdd-guide.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して tdd-guide.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → tdd-guide フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
16

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

TDDガイド

Jest、Pytest、JUnit、Vitestにおけるテストの生成、カバレッジの分析、および赤-緑-リファクタリングのワークフローをガイドするためのテスト駆動開発スキルです。


ワークフロー

コードからのテスト生成

  1. ソースコード(TypeScript、JavaScript、Python、Java)を提供します。
  2. ターゲットフレームワーク(Jest、Pytest、JUnit、Vitest)を指定します。
  3. 要件に従ってtest_generator.pyを実行します。
  4. 生成されたテストスタブを確認します。
  5. 検証: テストがコンパイルされ、ハッピーパス、エラーケース、エッジケースをカバーしていることを確認します。

カバレッジギャップの分析

  1. テストランナーからカバレッジレポートを生成します(npm test -- --coverage)。
  2. LCOV/JSON/XMLレポートに対してcoverage_analyzer.pyを実行します。
  3. 優先順位付けされたギャップ(P0/P1/P2)を確認します。
  4. カバーされていないパスに対して不足しているテストを生成します。
  5. 検証: カバレッジが目標しきい値(通常80%以上)を満たしていることを確認します。

新機能のTDD

  1. 最初に失敗するテストを作成します(RED)。
  2. tdd_workflow.py --phase redを実行して検証します。
  3. パスするための最小限のコードを実装します(GREEN)。
  4. tdd_workflow.py --phase greenを実行して検証します。
  5. テストをグリーンに保ちながらリファクタリングします(REFACTOR)。
  6. 検証: 各サイクル後にすべてのテストがパスすることを確認します。

テスト生成 — 入力 → 出力(Pytest)

入力ソース関数(math_utils.py):

def divide(a: float, b: float) -> float:
    if b == 0:
        raise ValueError("Cannot divide by zero")
    return a / b

コマンド:

python scripts/test_generator.py --input math_utils.py --framework pytest

生成されたテスト出力(test_math_utils.py):

import pytest
from math_utils import divide

class TestDivide:
    def test_divide_positive_numbers(self):
        assert divide(10, 2) == 5.0

    def test_divide_negative_numerator(self):
        assert divide(-10, 2) == -5.0

    def test_divide_float_result(self):
        assert divide(1, 3) == pytest.approx(0.333, rel=1e-3)

    def test_divide_by_zero_raises_value_error(self):
        with pytest.raises(ValueError, match="Cannot divide by zero"):
            divide(10, 0)

    def test_divide_zero_numerator(self):
        assert divide(0, 5) == 0.0

カバレッジ分析 — P0/P1/P2出力例

コマンド:

python scripts/coverage_analyzer.py --report lcov.info --threshold 80

出力例:

Coverage Report — Overall: 63% (threshold: 80%)

P0 — Critical gaps (uncovered error paths):
  auth/login.py:42-58   handle_expired_token()       0% covered
  payments/process.py:91-110  handle_payment_failure()   0% covered

P1 — High-value gaps (core logic branches):
  users/service.py:77   update_profile() — else branch  0% covered
  orders/cart.py:134    apply_discount() — zero-qty guard  0% covered

P2 — Low-risk gaps (utility / helper functions):
  utils/formatting.py:12  format_currency()            0% covered

Recommended: Generate tests for P0 items first to reach 80% threshold.

主要ツール

ツール 目的 使用法
test_generator.py コード/要件からテストケースを生成します python scripts/test_generator.py --input source.py --framework pytest
coverage_analyzer.py カバレッジレポートを解析・分析します python scripts/coverage_analyzer.py --report lcov.info --threshold 80
tdd_workflow.py 赤-緑-リファクタリングサイクルをガイドします python scripts/tdd_workflow.py --phase red --test test_auth.py
fixture_generator.py テストデータとモックを生成します python scripts/fixture_generator.py --entity User --count 5

追加スクリプト: framework_adapter.py(フレームワーク間の変換)、metrics_calculator.py(品質メトリクス)、format_detector.py(言語/フレームワークの検出)、output_formatter.py(CLI/デスクトップ/CI出力)。


入力要件

テスト生成の場合:

  • ソースコード(ファイルパスまたは貼り付けられたコンテンツ)
  • ターゲットフレームワーク(Jest、Pytest、JUnit、Vitest)
  • カバレッジスコープ(ユニット、統合、エッジケース)

カバレッジ分析の場合:

  • カバレッジレポートファイル(LCOV、JSON、またはXML形式)
  • オプション: コンテキストのためのソースコード
  • オプション: 目標しきい値パーセンテージ

TDDワークフローの場合:

  • 機能要件またはユーザーストーリー
  • 現在のフェーズ(RED、GREEN、REFACTOR)
  • テストコードと実装ステータス

制限事項

スコープ 詳細
ユニットテストに焦点 統合テストとE2Eテストには異なるパターンが必要です
静的分析 テストの実行やランタイム動作の測定はできません
言語サポート TypeScript、JavaScript、Python、Javaに最適です
レポート形式 LCOV、JSON、XMLのみ。他の形式は変換が必要です
生成されたテスト スキャフォールディングを提供します。複雑なロジックには人間のレビューが必要です

他のツールを使用する場合:

  • E2Eテスト: Playwright、Cypress、Selenium
  • パフォーマンステスト: k6、JMeter、Locust
  • セキュリティテスト: OWASP ZAP、Burp Suite
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

TDD Guide

Test-driven development skill for generating tests, analyzing coverage, and guiding red-green-refactor workflows across Jest, Pytest, JUnit, and Vitest.


Workflows

Generate Tests from Code

  1. Provide source code (TypeScript, JavaScript, Python, Java)
  2. Specify target framework (Jest, Pytest, JUnit, Vitest)
  3. Run test_generator.py with requirements
  4. Review generated test stubs
  5. Validation: Tests compile and cover happy path, error cases, edge cases

Analyze Coverage Gaps

  1. Generate coverage report from test runner (npm test -- --coverage)
  2. Run coverage_analyzer.py on LCOV/JSON/XML report
  3. Review prioritized gaps (P0/P1/P2)
  4. Generate missing tests for uncovered paths
  5. Validation: Coverage meets target threshold (typically 80%+)

TDD New Feature

  1. Write failing test first (RED)
  2. Run tdd_workflow.py --phase red to validate
  3. Implement minimal code to pass (GREEN)
  4. Run tdd_workflow.py --phase green to validate
  5. Refactor while keeping tests green (REFACTOR)
  6. Validation: All tests pass after each cycle

Examples

Test Generation — Input → Output (Pytest)

Input source function (math_utils.py):

def divide(a: float, b: float) -> float:
    if b == 0:
        raise ValueError("Cannot divide by zero")
    return a / b

Command:

python scripts/test_generator.py --input math_utils.py --framework pytest

Generated test output (test_math_utils.py):

import pytest
from math_utils import divide

class TestDivide:
    def test_divide_positive_numbers(self):
        assert divide(10, 2) == 5.0

    def test_divide_negative_numerator(self):
        assert divide(-10, 2) == -5.0

    def test_divide_float_result(self):
        assert divide(1, 3) == pytest.approx(0.333, rel=1e-3)

    def test_divide_by_zero_raises_value_error(self):
        with pytest.raises(ValueError, match="Cannot divide by zero"):
            divide(10, 0)

    def test_divide_zero_numerator(self):
        assert divide(0, 5) == 0.0

Coverage Analysis — Sample P0/P1/P2 Output

Command:

python scripts/coverage_analyzer.py --report lcov.info --threshold 80

Sample output:

Coverage Report — Overall: 63% (threshold: 80%)

P0 — Critical gaps (uncovered error paths):
  auth/login.py:42-58   handle_expired_token()       0% covered
  payments/process.py:91-110  handle_payment_failure()   0% covered

P1 — High-value gaps (core logic branches):
  users/service.py:77   update_profile() — else branch  0% covered
  orders/cart.py:134    apply_discount() — zero-qty guard  0% covered

P2 — Low-risk gaps (utility / helper functions):
  utils/formatting.py:12  format_currency()            0% covered

Recommended: Generate tests for P0 items first to reach 80% threshold.

Key Tools

Tool Purpose Usage
test_generator.py Generate test cases from code/requirements python scripts/test_generator.py --input source.py --framework pytest
coverage_analyzer.py Parse and analyze coverage reports python scripts/coverage_analyzer.py --report lcov.info --threshold 80
tdd_workflow.py Guide red-green-refactor cycles python scripts/tdd_workflow.py --phase red --test test_auth.py
fixture_generator.py Generate test data and mocks python scripts/fixture_generator.py --entity User --count 5

Additional scripts: framework_adapter.py (convert between frameworks), metrics_calculator.py (quality metrics), format_detector.py (detect language/framework), output_formatter.py (CLI/desktop/CI output).


Input Requirements

For Test Generation:

  • Source code (file path or pasted content)
  • Target framework (Jest, Pytest, JUnit, Vitest)
  • Coverage scope (unit, integration, edge cases)

For Coverage Analysis:

  • Coverage report file (LCOV, JSON, or XML format)
  • Optional: Source code for context
  • Optional: Target threshold percentage

For TDD Workflow:

  • Feature requirements or user story
  • Current phase (RED, GREEN, REFACTOR)
  • Test code and implementation status

Limitations

Scope Details
Unit test focus Integration and E2E tests require different patterns
Static analysis Cannot execute tests or measure runtime behavior
Language support Best for TypeScript, JavaScript, Python, Java
Report formats LCOV, JSON, XML only; other formats need conversion
Generated tests Provide scaffolding; require human review for complex logic

When to use other tools:

  • E2E testing: Playwright, Cypress, Selenium
  • Performance testing: k6, JMeter, Locust
  • Security testing: OWASP ZAP, Burp Suite

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。