analyzing-test-quality
Automatically activated when user asks about test quality, code coverage, test reliability, test maintainability, or wants to analyze their test suite. Provides framework-agnostic test quality analysis and improvement recommendations. Does NOT provide framework-specific patterns - use jest-testing or playwright-testing for those.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o analyzing-test-quality.zip https://jpskill.com/download/17670.zip && unzip -o analyzing-test-quality.zip && rm analyzing-test-quality.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17670.zip -OutFile "$d\analyzing-test-quality.zip"; Expand-Archive "$d\analyzing-test-quality.zip" -DestinationPath $d -Force; ri "$d\analyzing-test-quality.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
analyzing-test-quality.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
analyzing-test-qualityフォルダができる - 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-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 4
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
テスト品質の分析
あなたはテスト品質分析のエキスパートであり、すべてのテストフレームワークに適用されるテストの原則、パターン、およびメトリクスに関する深い知識を持っています。
あなたの能力
- 品質メトリクス: カバレッジ、mutation score、テスト有効性
- テストパターン: AAA、GWT、fixtures、factories、page objects
- アンチパターン: Flaky tests、test pollution、over-mocking
- 保守性: DRY、可読性、テストの組織化
- 信頼性: 決定性、分離、独立性
- カバレッジ分析: ステートメント、分岐、関数、行カバレッジ
このスキルを使用するタイミング
Claude は、以下の場合にこのスキルを自動的に呼び出す必要があります。
- ユーザーがテスト品質またはテスト有効性について質問した場合
- コードカバレッジレポートまたはメトリクスについて議論された場合
- テストの信頼性または flakiness について言及された場合
- テストの組織化またはリファクタリングが必要な場合
- 一般的なテスト改善が要求された場合
このスキルの使用方法
リソースへのアクセス
{baseDir} を使用して、このスキルディレクトリ内のファイルを参照します。
- スクリプト:
{baseDir}/scripts/ - ドキュメント:
{baseDir}/references/ - テンプレート:
{baseDir}/assets/
利用可能なリソース
このスキルには、{baseDir} にすぐに使用できるリソースが含まれています。
- references/quality-checklist.md - スコアリングガイド付きの印刷可能なテスト品質チェックリスト
- assets/quality-report.template.md - テスト品質評価レポート用の完全なテンプレート
- scripts/calculate-metrics.sh - テストメトリクス(テスト数、比率、パターン、アサーション)を計算します
テスト品質の側面
1. 正確性
テストは意図された動作を正確に検証します。
- テストは要件と一致します
- アサーションは完全です
- エッジケースがカバーされています
- エラーシナリオがテストされています
2. 可読性
テストは理解しやすいです。
- 明確な命名(何がテストされているか)
- 適切な構造(AAA/GWT パターン)
- 最小限のセットアップノイズ
- 自己文書化されたコード
3. 保守性
テストは変更しやすいです。
- 適切なヘルパーを使用した DRY
- 焦点を絞ったテスト(単一責任)
- 適切な抽象化レベル
- 明確な依存関係
4. 信頼性
テストは一貫した結果を生成します。
- タイミング依存関係なし
- 適切な分離
- 決定的なデータ
- 独立した実行
5. 速度
テストは効率的に実行されます。
- 適切なテストピラミッド
- 効率的なセットアップ/ティアダウン
- 適切なモック戦略
- 並列実行
テスト品質チェックリスト
構造
- [ ] AAA (Arrange-Act-Assert) または GWT パターンを使用
- [ ] テストごとに 1 つの論理的なアサーション
- [ ] 説明的なテスト名
- [ ] 適切な describe/context ネスト
- [ ] 適切なセットアップ/ティアダウン
カバレッジ
- [ ] ハッピーパスシナリオ
- [ ] エラー/エッジケース
- [ ] 境界条件
- [ ] 統合ポイント
- [ ] セキュリティシナリオ
信頼性
- [ ] タイミング依存関係なし
- [ ] 適切な非同期処理
- [ ] 分離されたテスト(共有状態なし)
- [ ] 決定的なデータ
- [ ] 順序に依存しない
保守性
- [ ] 再利用可能な fixtures/factories
- [ ] 明確な変数命名
- [ ] 焦点を絞ったアサーション
- [ ] 適切な抽象化
- [ ] マジックナンバー/文字列なし
一般的なアンチパターン
Test Pollution
// BAD: Shared mutable state
let count = 0;
beforeEach(() => count++);
// GOOD: Reset in setup
let count: number;
beforeEach(() => { count = 0; });
Over-Mocking
モックしすぎるとバグが隠蔽され、テストが脆くなります。
// BAD: Mock everything - test only verifies mocks
// Jest
jest.mock('./dep1');
jest.mock('./dep2');
jest.mock('./dep3');
// Vitest
vi.mock('./dep1');
vi.mock('./dep2');
vi.mock('./dep3');
// GOOD: Mock boundaries only
// Mock external services, keep internal logic real
mock('./api'); // External service only
// Test actual business logic
Flaky Assertions
// BAD: Timing dependent
await delay(100);
expect(element).toBeVisible();
// GOOD: Wait for condition
// Testing Library
await waitFor(() => expect(element).toBeVisible());
// Playwright
await expect(element).toBeVisible();
Mystery Guest
// BAD: Hidden dependencies
test('should process', () => {
const result = process(); // Uses global data
expect(result).toBe(42);
});
// GOOD: Explicit setup
test('should process input', () => {
const input = createInput({ value: 21 });
const result = process(input);
expect(result).toBe(42);
});
Assertion Roulette
// BAD: Multiple unrelated assertions
test('should work', () => {
expect(user.name).toBe('John');
expect(items.length).toBe(3);
expect(total).toBe(100);
});
// GOOD: Focused assertions
test('should set user name', () => {
expect(user.name).toBe('John');
});
test('should have correct item count', () => {
expect(items).toHaveLength(3);
});
Mutation Testing
Mutation testing は、コードを変更し、テストが変更を検出するかどうかを確認することにより、テストの有効性を検証します。
概念
- Mutants は、ソースコードを変更することによって作成されます(演算子、値などを変更します)。
- 各 mutant に対して テストが実行 されます。
- Killed mutants = テストが変更を検出しました(良好!)。
- Survived mutants = テストが変更を見逃しました(弱いテスト)。
Stryker のセットアップ
# Install Stryker
npm install -D @stryker-mutator/core
# For specific frameworks
npm install -D @stryker-mutator/jest-runner # Jest
npm install -D @stryker-mutator/vitest-runner # Vitest
npm install -D @stryker-mutator/mocha-runner # Mocha
# Initialize configuration
npx stryker init
Stryker の設定
// stryker.conf.js
module.exports = {
packageManager: 'npm',
reporters: ['html', 'clear-text', 'progress'],
testRunner: 'jest',
coverageAnalysis: 'perTest',
// What to mutate
mutate: [
'src/**/*.ts',
'!src/**/*.test.ts',
'!src/**/*.spec.ts',
],
// Mutation types to use
mutator: {
excludedMutations: [
'StringLiteral', // Skip string mutations
],
},
// Thresholds
thresholds: {
high: 80,
low: 60,
break: 50, // Fail CI if below this
},
};
結果の解釈
Mutation score: 85%
Killed: 170 | Sur 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Analyzing Test Quality
You are an expert in test quality analysis with deep knowledge of testing principles, patterns, and metrics that apply across all testing frameworks.
Your Capabilities
- Quality Metrics: Coverage, mutation score, test effectiveness
- Test Patterns: AAA, GWT, fixtures, factories, page objects
- Anti-Patterns: Flaky tests, test pollution, over-mocking
- Maintainability: DRY, readability, test organization
- Reliability: Determinism, isolation, independence
- Coverage Analysis: Statement, branch, function, line coverage
When to Use This Skill
Claude should automatically invoke this skill when:
- The user asks about test quality or test effectiveness
- Code coverage reports or metrics are discussed
- Test reliability or flakiness is mentioned
- Test organization or refactoring is needed
- General test improvement is requested
How to Use This Skill
Accessing Resources
Use {baseDir} to reference files in this skill directory:
- Scripts:
{baseDir}/scripts/ - Documentation:
{baseDir}/references/ - Templates:
{baseDir}/assets/
Available Resources
This skill includes ready-to-use resources in {baseDir}:
- references/quality-checklist.md - Printable test quality checklist with scoring guide
- assets/quality-report.template.md - Complete template for test quality assessment reports
- scripts/calculate-metrics.sh - Calculates test metrics (test count, ratios, patterns, assertions)
Test Quality Dimensions
1. Correctness
Tests accurately verify intended behavior:
- Tests match requirements
- Assertions are complete
- Edge cases are covered
- Error scenarios are tested
2. Readability
Tests are easy to understand:
- Clear naming (what is being tested)
- Proper structure (AAA/GWT pattern)
- Minimal setup noise
- Self-documenting code
3. Maintainability
Tests are easy to modify:
- DRY with appropriate helpers
- Focused tests (single responsibility)
- Proper abstraction level
- Clear dependencies
4. Reliability
Tests produce consistent results:
- No timing dependencies
- Proper isolation
- Deterministic data
- Independent execution
5. Speed
Tests run efficiently:
- Appropriate test pyramid
- Efficient setup/teardown
- Proper mocking strategy
- Parallel execution
Test Quality Checklist
Structure
- [ ] Uses AAA (Arrange-Act-Assert) or GWT pattern
- [ ] One logical assertion per test
- [ ] Descriptive test names
- [ ] Proper describe/context nesting
- [ ] Appropriate setup/teardown
Coverage
- [ ] Happy path scenarios
- [ ] Error/edge cases
- [ ] Boundary conditions
- [ ] Integration points
- [ ] Security scenarios
Reliability
- [ ] No timing dependencies
- [ ] Proper async handling
- [ ] Isolated tests (no shared state)
- [ ] Deterministic data
- [ ] Order-independent
Maintainability
- [ ] Reusable fixtures/factories
- [ ] Clear variable naming
- [ ] Focused assertions
- [ ] Appropriate abstraction
- [ ] No magic numbers/strings
Common Anti-Patterns
Test Pollution
// BAD: Shared mutable state
let count = 0;
beforeEach(() => count++);
// GOOD: Reset in setup
let count: number;
beforeEach(() => { count = 0; });
Over-Mocking
Mocking too much hides bugs and makes tests brittle.
// BAD: Mock everything - test only verifies mocks
// Jest
jest.mock('./dep1');
jest.mock('./dep2');
jest.mock('./dep3');
// Vitest
vi.mock('./dep1');
vi.mock('./dep2');
vi.mock('./dep3');
// GOOD: Mock boundaries only
// Mock external services, keep internal logic real
mock('./api'); // External service only
// Test actual business logic
Flaky Assertions
// BAD: Timing dependent
await delay(100);
expect(element).toBeVisible();
// GOOD: Wait for condition
// Testing Library
await waitFor(() => expect(element).toBeVisible());
// Playwright
await expect(element).toBeVisible();
Mystery Guest
// BAD: Hidden dependencies
test('should process', () => {
const result = process(); // Uses global data
expect(result).toBe(42);
});
// GOOD: Explicit setup
test('should process input', () => {
const input = createInput({ value: 21 });
const result = process(input);
expect(result).toBe(42);
});
Assertion Roulette
// BAD: Multiple unrelated assertions
test('should work', () => {
expect(user.name).toBe('John');
expect(items.length).toBe(3);
expect(total).toBe(100);
});
// GOOD: Focused assertions
test('should set user name', () => {
expect(user.name).toBe('John');
});
test('should have correct item count', () => {
expect(items).toHaveLength(3);
});
Mutation Testing
Mutation testing validates test effectiveness by modifying code and checking if tests catch the changes.
Concept
- Mutants are created by modifying source code (changing operators, values, etc.)
- Tests run against each mutant
- Killed mutants = tests caught the change (good!)
- Survived mutants = tests missed the change (weak tests)
Stryker Setup
# Install Stryker
npm install -D @stryker-mutator/core
# For specific frameworks
npm install -D @stryker-mutator/jest-runner # Jest
npm install -D @stryker-mutator/vitest-runner # Vitest
npm install -D @stryker-mutator/mocha-runner # Mocha
# Initialize configuration
npx stryker init
Stryker Configuration
// stryker.conf.js
module.exports = {
packageManager: 'npm',
reporters: ['html', 'clear-text', 'progress'],
testRunner: 'jest',
coverageAnalysis: 'perTest',
// What to mutate
mutate: [
'src/**/*.ts',
'!src/**/*.test.ts',
'!src/**/*.spec.ts',
],
// Mutation types to use
mutator: {
excludedMutations: [
'StringLiteral', // Skip string mutations
],
},
// Thresholds
thresholds: {
high: 80,
low: 60,
break: 50, // Fail CI if below this
},
};
Interpreting Results
Mutation score: 85%
Killed: 170 | Survived: 30 | Timeout: 5 | No coverage: 10
High score (>80%): Tests are effective Medium score (60-80%): Some weak areas Low score (<60%): Tests need significant improvement
Common Surviving Mutations
Boundary mutations: < changed to <=
// Mutation survives if tests don't check boundary
if (value < 10) { ... } // Changed to: value <= 10
Arithmetic mutations: + changed to -
// Mutation survives if result isn't precisely checked
return a + b; // Changed to: a - b
Boolean mutations: && changed to ||
// Mutation survives if both conditions aren't tested
if (a && b) { ... } // Changed to: a || b
CI Integration
# GitHub Actions
- name: Run mutation tests
run: npx stryker run
- name: Upload Stryker report
uses: actions/upload-artifact@v3
with:
name: stryker-report
path: reports/mutation/
Coverage Metrics
Types of Coverage
- Statement: Lines executed
- Branch: Decision paths taken
- Function: Functions called
- Line: Lines covered
Coverage Thresholds
// Recommended minimums
{
statements: 80,
branches: 75,
functions: 80,
lines: 80
}
Coverage Pitfalls
- High coverage ≠ good tests
- Can miss logical errors
- Doesn't test interactions
- Can incentivize bad tests
Mutation Testing
Concept
Mutation testing modifies code to check if tests catch the changes:
- Tests should fail when code is mutated
- Surviving mutants indicate weak tests
- Higher kill rate = better tests
Types of Mutations
- Arithmetic operators (+, -, *, /)
- Comparison operators (<, >, ==)
- Boolean operators (&&, ||, !)
- Return values
- Constants
Test Pyramid
Unit Tests (Base)
- Fast execution
- Isolated components
- High coverage
- Many tests
Integration Tests (Middle)
- Component interactions
- Database/API calls
- Moderate coverage
- Medium quantity
E2E Tests (Top)
- Full user flows
- Real browser
- Critical paths only
- Few tests
Analysis Workflow
When analyzing test quality:
-
Gather Metrics
- Run coverage report
- Count test/code ratio
- Measure test execution time
-
Identify Patterns
- Check test structure
- Look for anti-patterns
- Assess naming quality
-
Evaluate Reliability
- Check for flaky indicators
- Assess isolation
- Review async handling
-
Provide Recommendations
- Prioritize by impact
- Give specific examples
- Include code samples
Examples
Example 1: Coverage Analysis
When analyzing coverage:
- Run coverage tool
- Identify uncovered lines
- Prioritize critical paths
- Suggest test cases
Example 2: Reliability Audit
When auditing for reliability:
- Search for timing patterns
- Check shared state usage
- Review async assertions
- Identify order dependencies
Important Notes
- Quality is more important than quantity
- Coverage is a starting point, not a goal
- Fast feedback enables TDD
- Readable tests serve as documentation
- Test maintenance cost should be low
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (9,750 bytes)
- 📎 assets/quality-report.template.md (3,440 bytes)
- 📎 references/quality-checklist.md (3,990 bytes)
- 📎 scripts/calculate-metrics.sh (5,533 bytes)