关于 qe-coverage-analysis
面向 QA 团队的覆盖率分析 Skill,可检测覆盖缺口、评估风险并按代码关键性安排测试优先级。它包含次线性缺口检测和差异覆盖率分析,用于比较分支变更。
主要功能
- 01次线性覆盖缺口检测
- 02语句、分支和函数指标
- 03风险加权覆盖率评分
- 04差异覆盖率分析
- 05覆盖率阈值与质量门禁
- 06覆盖率报告和运行历史
适用场景
- 01查找未覆盖的关键代码
- 02按代码风险安排测试优先级
- 03比较不同分支的覆盖率
- 04为代码变更执行覆盖率要求
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ proffesor-for-testing/ agentic-qe --skill qe-coverage-analysis安装后在 Claude Code 中输入/qe-coverage-analysis确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
run-history.jsonevals/qe-coverage-analysis.yamlschemas/output.jsonscripts/validate-config.json详细介绍
QE 覆盖率分析
用途
指导使用 v3 的高级覆盖率分析能力,包括亚线性缺口检测算法、风险加权覆盖率评分,以及基于代码关键性的智能测试优先级排序。
激活时机
- 分析测试覆盖率时
- 识别覆盖率缺口时
- 确定测试工作的优先级时
- 设定覆盖率目标时
- 评估代码风险时
快速入门
# Analyze coverage with gap detection
aqe coverage analyze --source src/ --tests tests/
# Find high-risk uncovered code
aqe coverage gaps --risk-weighted --threshold 80
# Generate coverage report
aqe coverage report --format html --output coverage-report/
# Compare coverage between branches
aqe coverage diff --base main --head feature-branch
Agent 工作流
// Comprehensive coverage analysis
Task("Analyze coverage gaps", `
Perform O(log n) coverage analysis on src/:
- Calculate statement, branch, function coverage
- Identify uncovered critical paths
- Risk-weight gaps by code complexity and change frequency
- Recommend tests to write for maximum coverage impact
`, "qe-coverage-specialist")
// Risk-based prioritization
Task("Prioritize coverage effort", `
Analyze coverage gaps and prioritize by:
- Business criticality (payment, auth, data)
- Code complexity (cyclomatic > 10)
- Recent bug history
- Change frequency
Output prioritized list of files needing tests.
`, "qe-coverage-analyzer")
分析策略
1. 亚线性缺口检测
await coverageAnalyzer.detectGaps({
algorithm: 'sublinear', // O(log n) complexity
source: 'src/**/*.ts',
metrics: ['statement', 'branch', 'function'],
sampling: {
enabled: true,
confidence: 0.95,
maxSamples: 1000
}
});
2. 风险加权覆盖率
await coverageAnalyzer.riskWeightedAnalysis({
coverage: coverageReport,
riskFactors: {
complexity: { weight: 0.3, threshold: 10 },
changeFrequency: { weight: 0.25, window: '90d' },
bugHistory: { weight: 0.25, window: '180d' },
criticality: { weight: 0.2, tags: ['payment', 'auth'] }
},
output: {
riskScore: true,
prioritizedGaps: true
}
});
3. 差异覆盖率
await coverageAnalyzer.diffCoverage({
base: 'main',
head: 'feature-branch',
requirements: {
newCode: 80, // New code must have 80% coverage
modifiedCode: 'maintain', // Don't decrease existing
deletedCode: 'ignore'
}
});
覆盖率阈值
thresholds:
global:
statements: 80
branches: 75
functions: 85
lines: 80
per_file:
min_statements: 70
critical_paths: 90
new_code:
statements: 85
branches: 80
exceptions:
- path: "src/migrations/**"
reason: "Database migrations"
- path: "src/generated/**"
reason: "Auto-generated code"
覆盖率报告
interface CoverageAnalysis {
summary: {
statements: { covered: number; total: number; percentage: number };
branches: { covered: number; total: number; percentage: number };
functions: { covered: number; total: number; percentage: number };
};
gaps: {
file: string;
uncoveredLines: number[];
uncoveredBranches: BranchInfo[];
riskScore: number;
suggestedTests: string[];
}[];
trends: {
period: string;
coverageChange: number;
newGaps: number;
closedGaps: number;
};
recommendations: {
priority: 'critical' | 'high' | 'medium' | 'low';
file: string;
action: string;
expectedImpact: number;
}[];
}
质量门禁
quality_gates:
coverage:
block_merge:
- new_code_coverage < 80
- coverage_regression > 5
- critical_path_uncovered
warn:
- overall_coverage < 75
- branch_coverage < 70
metrics:
- track_trends: true
- alert_on_decline: 3 # consecutive PRs
运行历史
每次覆盖率分析后,将结果追加到此技能目录中的 run-history.json:
# Read current history, append new entry, write back
node -e "
const fs = require('fs');
const h = JSON.parse(fs.readFileSync('.claude/skills/qe-coverage-analysis/run-history.json'));
h.runs.push({date: new Date().toISOString().split('T')[0], statements_pct: STATEMENTS, branches_pct: BRANCHES, gaps_found: GAPS});
fs.writeFileSync('.claude/skills/qe-coverage-analysis/run-history.json', JSON.stringify(h, null, 2));
"
每次运行前读取 run-history.json,以发现趋势(例如“覆盖率连续 3 次下降”)。
技能组合
- 覆盖率下降? → 使用
/coverage-drop-investigator追查原因 - 需要更多测试 → 使用
/qe-test-generation填补缺口 - 验证质量 → 使用
/mutation-testing确保覆盖率代表质量 - 发布决策 → 将结果提供给
/qe-quality-assessment,评估是否满足部署要求
注意事项
- 高行覆盖率并不意味着测试质量高——覆盖率达到 100% 但断言为 0% 的情况在 Agent 输出中很常见。使用变异测试进行验证
- coverage-analysis 域的成功率为 86%——14% 的运行会在初始化时失败。务必验证结果并准备备用方案(例如手动覆盖率工具)
- 自学习流水线可能会悄然停止学习(状态行数天不变)——只有人工检查才能发现
协调
主要 Agent:qe-coverage-specialist、qe-coverage-analyzer、qe-gap-detector 协调器:qe-coverage-coordinator 相关技能:qe-test-generation、qe-quality-assessment
评论
支持 Markdown