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本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
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
$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. 下の青いボタンを押して
tdd-guide.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
tdd-guideフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-17
- 取得日時
- 2026-05-17
- 同梱ファイル
- 16
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
TDDガイド
Jest、Pytest、JUnit、Vitestにおけるテストの生成、カバレッジの分析、および赤-緑-リファクタリングのワークフローをガイドするためのテスト駆動開発スキルです。
ワークフロー
コードからのテスト生成
- ソースコード(TypeScript、JavaScript、Python、Java)を提供します。
- ターゲットフレームワーク(Jest、Pytest、JUnit、Vitest)を指定します。
- 要件に従って
test_generator.pyを実行します。 - 生成されたテストスタブを確認します。
- 検証: テストがコンパイルされ、ハッピーパス、エラーケース、エッジケースをカバーしていることを確認します。
カバレッジギャップの分析
- テストランナーからカバレッジレポートを生成します(
npm test -- --coverage)。 - LCOV/JSON/XMLレポートに対して
coverage_analyzer.pyを実行します。 - 優先順位付けされたギャップ(P0/P1/P2)を確認します。
- カバーされていないパスに対して不足しているテストを生成します。
- 検証: カバレッジが目標しきい値(通常80%以上)を満たしていることを確認します。
新機能のTDD
- 最初に失敗するテストを作成します(RED)。
tdd_workflow.py --phase redを実行して検証します。- パスするための最小限のコードを実装します(GREEN)。
tdd_workflow.py --phase greenを実行して検証します。- テストをグリーンに保ちながらリファクタリングします(REFACTOR)。
- 検証: 各サイクル後にすべてのテストがパスすることを確認します。
例
テスト生成 — 入力 → 出力(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
- Provide source code (TypeScript, JavaScript, Python, Java)
- Specify target framework (Jest, Pytest, JUnit, Vitest)
- Run
test_generator.pywith requirements - Review generated test stubs
- Validation: Tests compile and cover happy path, error cases, edge cases
Analyze Coverage Gaps
- Generate coverage report from test runner (
npm test -- --coverage) - Run
coverage_analyzer.pyon LCOV/JSON/XML report - Review prioritized gaps (P0/P1/P2)
- Generate missing tests for uncovered paths
- Validation: Coverage meets target threshold (typically 80%+)
TDD New Feature
- Write failing test first (RED)
- Run
tdd_workflow.py --phase redto validate - Implement minimal code to pass (GREEN)
- Run
tdd_workflow.py --phase greento validate - Refactor while keeping tests green (REFACTOR)
- 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` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (5,496 bytes)
- 📎 assets/expected_output.json (2,404 bytes)
- 📎 assets/sample_input_python.json (1,443 bytes)
- 📎 assets/sample_input_typescript.json (1,469 bytes)
- 📎 README.md (18,528 bytes)
- 📎 references/ci-integration.md (4,017 bytes)
- 📎 references/framework-guide.md (4,316 bytes)
- 📎 references/tdd-best-practices.md (3,516 bytes)
- 📎 scripts/coverage_analyzer.py (15,502 bytes)
- 📎 scripts/fixture_generator.py (14,311 bytes)
- 📎 scripts/format_detector.py (12,207 bytes)
- 📎 scripts/framework_adapter.py (14,834 bytes)
- 📎 scripts/metrics_calculator.py (15,476 bytes)
- 📎 scripts/output_formatter.py (12,734 bytes)
- 📎 scripts/tdd_workflow.py (16,968 bytes)
- 📎 scripts/test_generator.py (14,617 bytes)