AgentSkillsCN

Test Coverage Analysis

测试覆盖率分析

SKILL.md

Test Coverage Analysis

Skill Purpose: Analyze test coverage, enforce thresholds, and report coverage gaps for code quality gates.


Core Skill Pattern

Objective: Maintain measurable test coverage and prevent regressions in critical areas.

Universal Pattern:

  1. Define coverage thresholds by scope
  2. Collect coverage on CI and locally
  3. Generate HTML/JSON reports
  4. Identify hot spots and low coverage areas
  5. Track coverage changes over time

Key Decisions (Project-Specific):

  • Global vs per-package thresholds
  • Branch vs line coverage weighting
  • Exclusions for generated or vendor code
  • Coverage artifacts retention

Project-Specific Implementation Notes

Customize per project:

  • Decide minimum coverage by module criticality
  • Align coverage gates with quality gates
  • Store coverage reports as CI artifacts

Example Implementation (Jest)

js
// jest.config.js
module.exports = {
  collectCoverage: true,
  collectCoverageFrom: [
    'app/**/*.{ts,tsx}',
    'lib/**/*.{ts,tsx}',
    '!**/*.d.ts',
    '!**/node_modules/**'
  ],
  coverageThreshold: {
    global: {
      branches: 80,
      functions: 80,
      lines: 80,
      statements: 80
    }
  },
  coverageReporters: ['text', 'json', 'html']
};

Best Practices

  1. Gate merges on coverage thresholds
  2. Track coverage deltas per PR
  3. Prioritize coverage in high-risk areas
  4. Avoid gaming coverage with low-value tests
  5. Keep exclusions explicit and minimal

Stop Conditions

STOP and escalate if:

  • Coverage thresholds are undefined
  • Reports are missing on CI
  • Coverage excludes critical modules

Skill Version: 1.0.0