AgentSkillsCN

test-coverage-analyzer

分析测试覆盖率,识别薄弱环节,并提出针对性测试方案,以提升关键路径上的测试覆盖率。

SKILL.md
--- frontmatter
name: test-coverage-analyzer
description: Analyze test coverage, identify gaps, and suggest tests to improve coverage in critical paths.

Test Coverage Analyzer

When to Use

  • After implementing new features to ensure coverage.
  • Before releases to validate quality.
  • When refactoring to ensure regression protection.
  • During code reviews to assess test quality.

Coverage Metrics

MetricTargetCritical
Line Coverage80%+60%+
Branch Coverage75%+50%+
Function Coverage90%+70%+

Workflow

1. Generate Coverage Report

bash
# Python (pytest)
pytest --cov=src --cov-report=html --cov-report=term-missing

# JavaScript (Jest)
npm test -- --coverage

# Go
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

# Rust
cargo tarpaulin --out Html

2. Analyze Gaps

Focus on:

  • Critical paths: Auth, payments, data handling.
  • Error handling: Exception branches, edge cases.
  • Business logic: Core domain functions.
  • Integration points: API calls, database operations.

3. Prioritize Tests

PriorityWhat to Test
P0Security-critical code (auth, encryption)
P1Business-critical logic (payments, core features)
P2Error handling and edge cases
P3Utility functions and helpers
P4UI components (if not critical)

4. Generate Test Suggestions

For each uncovered function:

  • Identify input types and ranges.
  • List edge cases (null, empty, boundary).
  • Note error conditions to test.
  • Suggest mocking requirements.

Test Suggestion Template

markdown
## Missing Coverage: `function_name` (file.py:42)

### Current Coverage: 45% (lines 42-60 uncovered)

### Suggested Tests:

#### Happy Path
```python
def test_function_name_success():
    result = function_name(valid_input)
    assert result == expected_output

Edge Cases

python
def test_function_name_empty_input():
    with pytest.raises(ValueError):
        function_name("")

def test_function_name_boundary():
    result = function_name(MAX_VALUE)
    assert result == expected_boundary

Error Handling

python
def test_function_name_handles_timeout():
    with mock.patch('module.external_call', side_effect=TimeoutError):
        result = function_name(input)
        assert result == fallback_value
code

## Output Checklist
- [ ] Coverage report generated.
- [ ] Critical path coverage verified.
- [ ] Gap analysis completed.
- [ ] Test suggestions for uncovered code.
- [ ] Priority ranking for new tests.