Update nexus wiki content
This commit is contained in:
55
wiki/concepts/Test-Coverage-Analysis.md
Normal file
55
wiki/concepts/Test-Coverage-Analysis.md
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
title: "Test Coverage Analysis"
|
||||
type: concept
|
||||
tags: [testing, coverage, quality]
|
||||
sources: [testing-test-results-analyzer]
|
||||
last_updated: 2026-04-28
|
||||
---
|
||||
|
||||
## Definition
|
||||
|
||||
测试覆盖率分析——通过量化代码被执行的比例来评估测试的全面性,识别测试缺口并按风险优先级排序改进方向。
|
||||
|
||||
## Coverage Dimensions
|
||||
|
||||
| 维度 | 说明 | 目标 |
|
||||
|------|------|------|
|
||||
| 行覆盖率 (Line Coverage) | 被执行代码行数 / 总代码行数 | ≥80% |
|
||||
| 分支覆盖率 (Branch Coverage) | 已覆盖分支数 / 总分支数 | ≥75% |
|
||||
| 函数覆盖率 (Function Coverage) | 被调用函数数 / 总函数数 | ≥90% |
|
||||
| 语句覆盖率 (Statement Coverage) | 已执行语句数 / 总语句数 | ≥80% |
|
||||
|
||||
## Key Methods
|
||||
|
||||
- **Gap Analysis**:识别覆盖率 < 80% 的文件,结合文件变更频率和业务关键性计算改进优先级。
|
||||
- **Risk-Based Coverage Prioritization**:按文件业务重要性 × 变更频率 × 当前覆盖率计算改进优先级。
|
||||
- **Coverage Trend Tracking**:跨版本跟踪覆盖率变化,检测回归。
|
||||
|
||||
## Implementation (Python)
|
||||
|
||||
```python
|
||||
# 来自 TestResultsAnalyzer 的参考实现
|
||||
coverage_stats = {
|
||||
'line_coverage': test_results['coverage']['lines']['pct'],
|
||||
'branch_coverage': test_results['coverage']['branches']['pct'],
|
||||
'function_coverage': test_results['coverage']['functions']['pct'],
|
||||
'statement_coverage': test_results['coverage']['statements']['pct']
|
||||
}
|
||||
|
||||
# 识别覆盖缺口
|
||||
for file_path, file_coverage in uncovered_files.items():
|
||||
if file_coverage['lines']['pct'] < 80:
|
||||
gap_analysis.append({
|
||||
'file': file_path,
|
||||
'coverage': file_coverage['lines']['pct'],
|
||||
'risk_level': assess_file_risk(file_path, file_coverage),
|
||||
'priority': calculate_coverage_priority(file_path, file_coverage)
|
||||
})
|
||||
```
|
||||
|
||||
## Connections
|
||||
|
||||
- [[Quality-Metrics]]:覆盖率是核心质量指标之一。
|
||||
- [[Defect-Prediction]]:覆盖缺口区域通常也是缺陷高发区域。
|
||||
- [[Release-Readiness-Assessment]]:覆盖率是发布门控条件之一。
|
||||
- [[Failure-Pattern-Analysis]]:低覆盖率与高失败率往往相关。
|
||||
Reference in New Issue
Block a user