mcpField
T
testgen

testgen

github.com/0xdarkmatterテスト・品質7857 回インストール2 週間前に更新
リポジトリ

testgen について

testgenは、プロジェクトの言語や規約に合わせてテストを生成するスキルです。対象とテストフレームワークを分析し、ファイル種別に応じて処理を振り分け、E2Eテストにも対応します。

主な機能

  1. 01対象を分析し既存テストを確認
  2. 02テストフレームワークと規約の検出
  3. 03ファイル種別に応じた生成処理
  4. 04テストの重点と深さの指定
  5. 05複数言語とE2Eテストに対応
  6. 06ビジュアルモードでChrome DevTools MCPを利用

活用シーン

  1. 01関数やファイルのテスト生成
  2. 02プロジェクトのテストカバレッジ拡充
  3. 03既存のテスト規約に沿った作成
  4. 04ビジュアルモードでの画面テスト

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/0xdarkmatter/claude-mods --skill testgen

インストール後、Claude Code で/testgenを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

frameworks.md
visual-testing.md
assets/
.gitkeep
references/
.gitkeep
scripts/
.gitkeep

詳細

TestGen スキル - AI テスト生成

フレームワークの自動検出、スキルを事前読み込みした汎用ディスパッチ、プロジェクトの規約との適合により、包括的なテストを生成します。

アーキテクチャ

testgen <target> [--type] [--focus] [--depth]
    │
    ├─→ Step 1: Analyze Target
    │     ├─ File exists? → Read and parse
    │     ├─ Function specified? → Extract signature
    │     ├─ Directory? → List source files
    │     └─ Find existing tests (avoid duplicates)
    │
    ├─→ Step 2: Detect Framework (parallel)
    │     ├─ package.json → jest/vitest/mocha/cypress/playwright
    │     ├─ pyproject.toml → pytest/unittest
    │     ├─ go.mod → go test
    │     ├─ Cargo.toml → cargo test
    │     ├─ composer.json → phpunit/pest
    │     └─ Check existing test patterns
    │
    ├─→ Step 3: Load Project Standards
    │     ├─ AGENTS.md, CLAUDE.md conventions
    │     ├─ Existing test file structure
    │     └─ Naming conventions (*.test.ts vs *.spec.ts)
    │
    ├─→ Step 4: Route to Test Generator (general-purpose + skill preload)
    │     ├─ .ts → general-purpose, preload typescript-ops
    │     ├─ .tsx/.jsx → general-purpose, preload react-ops
    │     ├─ .vue → general-purpose, preload vue-ops
    │     ├─ .py → general-purpose, preload python-pytest-ops
    │     ├─ .go → general-purpose, preload go-ops
    │     ├─ .rs → general-purpose, preload rust-ops
    │     ├─ .php → general-purpose, preload laravel-ops
    │     ├─ E2E/Cypress → general-purpose, preload cypress-ops
    │     ├─ Playwright → general-purpose, preload typescript-ops
    │     ├─ Shell/bash → general-purpose, preload bash-ops
    │     ├─ --visual → Chrome DevTools MCP
    │     └─ Multi-file → parallel general-purpose dispatch
    │
    ├─→ Step 5: Generate Tests
    │     ├─ Create test file in correct location
    │     ├─ Follow detected conventions
    │     └─ Include: happy path, edge cases, error handling
    │
    └─→ Step 6: Integration
          ├─ Auto-create task (TaskCreate) for verification
          └─ Suggest: run tests, /review, /save

実行手順

ステップ 1:対象を分析する
# Check if target exists
test -f "$TARGET" && echo "FILE" || test -d "$TARGET" && echo "DIRECTORY"

# For function-specific: extract signature
command -v ast-grep >/dev/null 2>&1 && ast-grep -p "function $FUNCTION_NAME" "$FILE"

# Fallback to ripgrep
rg "(?:function|const|def|public|private)\s+$FUNCTION_NAME" "$FILE" -A 10

既存のテストを確認します:

fd -e test.ts -e spec.ts -e test.js -e spec.js | rg "$BASENAME"
fd "test_*.py" | rg "$BASENAME"
ステップ 2:フレームワークを検出する

JavaScript/TypeScript:

cat package.json 2>/dev/null | jq -r '.devDependencies | keys[]' | grep -E 'jest|vitest|mocha|cypress|playwright|@testing-library'

Python:

grep -E "pytest|unittest|nose" pyproject.toml setup.py requirements*.txt 2>/dev/null

Go:

test -f go.mod && echo "go test available"

Rust:

test -f Cargo.toml && echo "cargo test available"

PHP:

cat composer.json 2>/dev/null | jq -r '.["require-dev"] | keys[]' | grep -E 'phpunit|pest|codeception'
ステップ 3:プロジェクトの標準を読み込む
# Claude Code conventions
cat AGENTS.md 2>/dev/null | head -50
cat CLAUDE.md 2>/dev/null | head -50

# Test config files
cat jest.config.* vitest.config.* pytest.ini pyproject.toml 2>/dev/null | head -30

テスト配置の規約:

# JavaScript
src/utils/helper.ts → src/utils/__tests__/helper.test.ts  # __tests__ folder
                    → src/utils/helper.test.ts            # co-located
                    → tests/utils/helper.test.ts          # separate tests/

# Python
app/utils/helper.py → tests/test_helper.py               # tests/ folder
                    → tests/utils/test_helper.py         # mirror structure

# Go
pkg/auth/token.go → pkg/auth/token_test.go               # co-located (required)

# Rust
src/auth.rs → src/auth.rs (mod tests { ... })            # inline tests
            → tests/auth_test.rs                          # integration tests
ステップ 4:テストジェネレーターに振り分ける

ディスパッチではスキルを優先します。汎用の general-purpose サブエージェントは、テストを生成する前に関連する -ops スキルを事前に読み込みます。

ファイルパターンディスパッチ事前読み込み
*.tsgeneral-purposeskills/typescript-ops/SKILL.md
*.tsx, *.jsxgeneral-purposeskills/react-ops/SKILL.md + skills/typescript-ops/SKILL.md
*.vuegeneral-purposeskills/vue-ops/SKILL.md + skills/typescript-ops/SKILL.md
*.pygeneral-purposeskills/python-pytest-ops/SKILL.md
*.gogeneral-purposeskills/go-ops/SKILL.md
*.rsgeneral-purposeskills/rust-ops/SKILL.md
*.phpgeneral-purposeskills/laravel-ops/SKILL.md
*.cy.ts, cypress/*general-purposeskills/cypress-ops/SKILL.md + skills/typescript-ops/SKILL.md
*.spec.ts (Playwright)general-purposeskills/playwright-ops/SKILL.md + skills/typescript-ops/SKILL.md
playwright/*, e2e/*general-purposeskills/playwright-ops/SKILL.md + skills/typescript-ops/SKILL.md
*.sh, *.bashgeneral-purposeskills/bash-ops/SKILL.md
(--visual フラグ)Chrome DevTools MCPskills/typescript-ops/SKILL.md

Agent ツールで呼び出します:

Agent tool with subagent_type: "general-purpose" (or surviving specialist from table)
model: "sonnet"
Prompt includes:
  - Skill preloading (domain knowledge):
    "First, read these files for testing context:
     - Read: skills/security-ops/references/owasp-top10-a01-a05.md
     - Read: skills/security-ops/references/owasp-top10-a06-a10.md
     - Read: skills/testing-ops/SKILL.md
     - Read: [Preload column for the matched file pattern]"
  - Source file content
  - Function signatures to test
  - Detected framework and conventions
  - Requested test type and focus

言語別の事前読み込み(上記の事前読み込みセクションに追加):

言語追加の事前読み込み理由
Pythonskills/python-pytest-ops/SKILL.mdフィクスチャ、マーク、パラメーター化、非同期テスト
Goskills/go-ops/SKILL.mdテーブル駆動テスト、ベンチマーク、testify
Rustskills/rust-ops/SKILL.mdプロパティテスト、criterion、proptest
ステップ 5:テストを生成する

--focus に基づくテストカテゴリ:

フォーカス生成する内容
happy通常の入力、期待される出力
edge境界値、空の入力、null
error無効な入力、例外、エラー処理
all上記すべて(デフォルト)

深度レベル:

深度カバレッジ
quickハッピーパスのみ。関数あたり 1~2 件のテスト
normalハッピーパスと一般的なエッジケース(デフォルト)
thorough包括的なテスト:すべてのパス、モック、非同期処理
ステップ 6:統合する

タスクを自動作成します:

TaskCreate:
  subject: "Run generated tests for src/auth.ts"
  description: "Verify generated tests pass and review edge cases"
  activeForm: "Running generated tests for auth.ts"

次のステップを提案します:

Tests generated: src/auth.test.ts

Next steps:
1. Run tests: npm test src/auth.test.ts
2. Review and refine edge cases
3. Use /save to persist tasks across sessions

振り分けの詳細

TypeScript/JavaScript(typescript-ops を事前読み込み)
  • 適切な型のインポート
  • ジェネリック型の処理
  • async/await パターン
  • モックの型付け
React/JSX(react-ops を事前読み込み)
  • React Testing Library のパターン
  • コンポーネントのレンダリングテスト
  • フックのテスト(renderHook)
  • アクセシビリティクエリ(getByRole)
Vue(vue-ops を事前読み込み)
  • Vue Test Utils のパターン
  • Composition API のテスト
  • Pinia ストアのモック
Python(python-pytest-ops を事前読み込み)
  • pytest フィクスチャ
  • パラメーター化テスト
  • モック/パッチのパターン
  • 非同期テストの処理
Go(go-ops を事前読み込み)
  • テーブル駆動テスト([]struct パターン)
  • testing.T とサブテスト(t.Run)
  • Testify アサーション(検出された場合)
  • ベンチマーク関数(testing.B)
  • 並列テスト(t.Parallel())
Rust(rust-ops を事前読み込み)
  • #[test] 属性付き関数
  • #[cfg(test)] モジュールの構成
  • エラーテスト向けの #[should_panic]
  • プロパティテスト向けの proptest/quickcheck
PHP/Laravel(laravel-ops を事前読み込み)
  • PHPUnit/Pest のパターン
  • データベーストランザクション
  • ファクトリーの使用
E2E/Cypress(cypress-ops を事前読み込み)
  • ページオブジェクトのパターン
  • カスタムコマンド
  • ネットワークリクエストのスタブ化
Shell/bash(bash-ops をプリロード)
  • bats / shunit2 のパターン
  • 外部コマンドのスタブ化
  • 終了コードと stderr のアサーション
Playwright(typescript-ops をプリロード)
  • ページオブジェクトモデルのパターン
  • ロケーター戦略
  • ビジュアルリグレッションテスト

CLI ツールの統合

ツール目的代替手段
jqpackage.json の解析Read ツール
rg既存テストの検索Grep ツール
ast-grep関数シグネチャの解析ripgrep パターン
fdテストファイルの検索Glob ツール
Chrome DevTools MCPビジュアルテスト(--visual)Playwright/Cypress

フォールバック処理:

command -v jq >/dev/null 2>&1 && cat package.json | jq '.devDependencies' || cat package.json

参考ファイル

フレームワーク固有のコード例については、以下を参照してください。

  • frameworks.md - サポート対象のすべての言語を対象とした完全なテスト例
  • visual-testing.md - --visual フラグ向けの Chrome DevTools 統合

統合

コマンド関連性
/reviewコミット前に生成されたテストをレビューする
/explainテスト前に複雑なコードを理解する
/saveテストカバレッジの目標を追跡する

コメント