Quality Metrics
Test Coverage Metrics
Code Coverage Types
- Line Coverage: Percentage of executable lines executed
- Branch Coverage: Percentage of conditional branches taken
- Function Coverage: Percentage of functions/methods called
- Statement Coverage: Percentage of statements executed
- Condition Coverage: Percentage of boolean sub-conditions evaluated
Coverage Targets
Critical Business Logic: 90-100%
Core Application Code: 80-90%
Utility/Helper Code: 70-80%
Configuration/Setup Code: 50-70%
Coverage Tools
- JavaScript: Istanbul, nyc, Jest coverage
- Python: pytest-cov, coverage.py
- Java: JaCoCo, Cobertura
- .NET: dotCover, Coverlet
- Go: go test -cover
Coverage Best Practices
- Focus on meaningful coverage, not just percentage
- Prioritize coverage of critical paths
- Track coverage trends over time
- Set coverage gates in CI/CD
- Review uncovered code regularly
Code Quality Metrics
Cyclomatic Complexity
- Measures code complexity based on control flow
- Higher complexity = harder to test and maintain
- Target: < 10 per function/method
Complexity Levels:
1-10: Simple, low risk
11-20: Moderate complexity, medium risk
21-50: High complexity, high risk
50+: Very high complexity, very high risk
Maintainability Index
- Composite metric combining complexity, volume, and structure
- Scale: 0-100 (higher is better)
- Target: > 70
Maintainability Levels:
85-100: Highly maintainable
70-84: Moderately maintainable
50-69: Difficult to maintain
0-49: Very difficult to maintain
Code Duplication
- Percentage of duplicated code
- Target: < 5%
- High duplication indicates need for refactoring
Code Smells
- Long Methods: Methods > 50 lines
- Large Classes: Classes > 500 lines
- Deep Nesting: Nesting > 4 levels
- Long Parameter Lists: > 4 parameters
- Feature Envy: Methods using other objects more than their own
Technical Debt Ratio
Technical Debt Ratio = Cost to Fix Issues / Cost to Develop New Features
Target: < 5%
Defect Metrics
Defect Density
- Defects per thousand lines of code (KLOC)
- Defects per function point
- Defects per module/component
Defect Density = Total Defects / Size Metric (KLOC, FP)
Target: < 1 defect per KLOC
Defect Removal Efficiency (DRE)
- Percentage of defects found before release
- Higher is better
DRE = (Defects Found Before Release / Total Defects) × 100
Target: > 90%
Defect Leakage
- Percentage of defects found after release
- Lower is better
Defect Leakage = (Defects Found After Release / Total Defects) × 100
Target: < 10%
Defect Age
- Time from defect introduction to detection
- Time from defect detection to resolution
Defect Age = Detection Date - Introduction Date
Resolution Time = Resolution Date - Detection Date
Target: < 7 days for critical defects
Defect Severity Distribution
- Critical: System failure, data loss
- High: Major functionality broken
- Medium: Minor functionality broken
- Low: Cosmetic issues, typos
Defect Trend Analysis
- Track defects over time
- Identify patterns and trends
- Correlate with code changes
- Predict future defect rates
Quality Gates and Acceptance Criteria
Quality Gate Examples
Code Quality Gate:
- Code coverage ≥ 80%
- No critical or high severity defects
- Cyclomatic complexity ≤ 10
- No security vulnerabilities
- All tests passing
Performance Gate:
- p95 response time < 500ms
- Error rate < 0.1%
- Throughput ≥ 1000 RPS
- CPU utilization < 70%
Security Gate:
- No high/critical vulnerabilities
- OWASP Top 10 compliance
- Dependency scan clean
- Authentication/authorization tested
Acceptance Criteria
- Functional Requirements: All features work as specified
- Non-Functional Requirements: Performance, security, usability met
- Test Coverage: Minimum coverage thresholds met
- Defect Standards: No defects above acceptable severity
- Documentation: All documentation complete and accurate
Test Reporting and Dashboards
Test Execution Reports
- Total tests run
- Pass/fail counts and percentages
- Test execution time
- Flaky test identification
- Test failure categorization
Coverage Reports
- Line, branch, function coverage
- Coverage by module/component
- Uncovered code highlighting
- Coverage trends over time
- Coverage comparison between branches
Defect Reports
- Open defects by severity
- Defect trends and patterns
- Defect age distribution
- Defect resolution time
- Defect density by module
Performance Reports
- Response time metrics (p50, p95, p99)
- Throughput metrics
- Error rates
- Resource utilization
- Performance trends over time
Dashboard Elements
- Overall quality score
- Test coverage gauge
- Defect trend chart
- Performance metrics
- Build health status
- Quality gate status
QA KPIs and Metrics Tracking
Process Metrics
- Test Execution Time: Time to run test suite
- Test Automation Rate: Percentage of tests automated
- Test Case Count: Total number of test cases
- Test Case Execution: Number of tests executed per period
- Defect Detection Rate: Defects found per testing hour
Product Metrics
- Defect Escape Rate: Defects found in production
- Mean Time to Detection: Time to find defects
- Mean Time to Resolution: Time to fix defects
- Customer Reported Defects: Defects reported by users
- Test Coverage: Code, feature, and requirement coverage
Team Metrics
- Test Case Productivity: Test cases created per person-hour
- Automation Productivity: Automated tests created per person-hour
- Defect Detection Efficiency: Defects found per person-hour
- Test Execution Efficiency: Tests executed per person-hour
Quality Metrics
- Overall Quality Score: Composite quality metric
- Test Pass Rate: Percentage of passing tests
- Defect Density: Defects per size metric
- Code Quality Score: Based on complexity, duplication, smells
- Performance Score: Based on response time, throughput, errors
Metrics Dashboard
Quality Dashboard:
┌─────────────────────────────────────────┐
│ Overall Quality Score: 87/100 │
├─────────────────────────────────────────┤
│ Test Coverage: 85% │
│ ├─ Line: 87% │
│ ├─ Branch: 82% │
│ └─ Function: 90% │
├─────────────────────────────────────────┤
│ Code Quality: 82/100 │
│ ├─ Complexity: 8.2 avg │
│ ├─ Duplication: 3.1% │
│ └─ Maintainability: 78 │
├─────────────────────────────────────────┤
│ Defects: 12 open │
│ ├─ Critical: 1 │
│ ├─ High: 3 │
│ ├─ Medium: 5 │
│ └─ Low: 3 │
├─────────────────────────────────────────┤
│ Performance: 92/100 │
│ ├─ p95 Response: 420ms │
│ ├─ Throughput: 1250 RPS │
│ └─ Error Rate: 0.05% │
└─────────────────────────────────────────┘
Metrics Collection and Analysis
Data Collection
- Automated collection from CI/CD pipelines
- Integration with test frameworks
- Real-time monitoring and alerts
- Historical data storage
- Data normalization and aggregation
Analysis Techniques
- Trend analysis over time
- Comparison between branches/releases
- Correlation with code changes
- Root cause analysis of quality issues
- Predictive analytics for quality forecasting
Reporting Frequency
- Real-time: Build status, test failures, critical defects
- Daily: Test execution, defect updates, performance metrics
- Weekly: Quality trends, coverage reports, team metrics
- Monthly: Quality scorecards, process improvements, strategic insights
- Quarterly: Quality reviews, goal setting, process optimization
Continuous Improvement
- Identify quality trends and patterns
- Set quality goals and targets
- Track progress toward goals
- Implement process improvements based on metrics
- Celebrate quality achievements
1---2name: quality-metrics3description: Test coverage, code quality, defect metrics, and QA KPIs4---5
6# Quality Metrics
7
8## Test Coverage Metrics
9
10### Code Coverage Types
11- **Line Coverage**: Percentage of executable lines executed
12- **Branch Coverage**: Percentage of conditional branches taken
13- **Function Coverage**: Percentage of functions/methods called
14- **Statement Coverage**: Percentage of statements executed
15- **Condition Coverage**: Percentage of boolean sub-conditions evaluated
16
17### Coverage Targets
18```
19Critical Business Logic: 90-100%
20Core Application Code: 80-90%
21Utility/Helper Code: 70-80%
22Configuration/Setup Code: 50-70%
23```
24
25### Coverage Tools
26- **JavaScript**: Istanbul, nyc, Jest coverage
27- **Python**: pytest-cov, coverage.py
28- **Java**: JaCoCo, Cobertura
29- **.NET**: dotCover, Coverlet
30- **Go**: go test -cover
31
32### Coverage Best Practices
33- Focus on meaningful coverage, not just percentage
34- Prioritize coverage of critical paths
35- Track coverage trends over time
36- Set coverage gates in CI/CD
37- Review uncovered code regularly
38
39## Code Quality Metrics
40
41### Cyclomatic Complexity
42- Measures code complexity based on control flow
43- Higher complexity = harder to test and maintain
44- Target: < 10 per function/method
45
46```
47Complexity Levels:
481-10: Simple, low risk
4911-20: Moderate complexity, medium risk
5021-50: High complexity, high risk
5150+: Very high complexity, very high risk
52```
53
54### Maintainability Index
55- Composite metric combining complexity, volume, and structure
56- Scale: 0-100 (higher is better)
57- Target: > 70
58
59```
60Maintainability Levels:
6185-100: Highly maintainable
6270-84: Moderately maintainable
6350-69: Difficult to maintain
640-49: Very difficult to maintain
65```
66
67### Code Duplication
68- Percentage of duplicated code
69- Target: < 5%
70- High duplication indicates need for refactoring
71
72### Code Smells
73- **Long Methods**: Methods > 50 lines
74- **Large Classes**: Classes > 500 lines
75- **Deep Nesting**: Nesting > 4 levels
76- **Long Parameter Lists**: > 4 parameters
77- **Feature Envy**: Methods using other objects more than their own
78
79### Technical Debt Ratio
80```
81Technical Debt Ratio = Cost to Fix Issues / Cost to Develop New Features
82Target: < 5%
83```
84
85## Defect Metrics
86
87### Defect Density
88- Defects per thousand lines of code (KLOC)
89- Defects per function point
90- Defects per module/component
91
92```
93Defect Density = Total Defects / Size Metric (KLOC, FP)
94Target: < 1 defect per KLOC
95```
96
97### Defect Removal Efficiency (DRE)
98- Percentage of defects found before release
99- Higher is better
100
101```
102DRE = (Defects Found Before Release / Total Defects) × 100
103Target: > 90%
104```
105
106### Defect Leakage
107- Percentage of defects found after release
108- Lower is better
109
110```
111Defect Leakage = (Defects Found After Release / Total Defects) × 100
112Target: < 10%
113```
114
115### Defect Age
116- Time from defect introduction to detection
117- Time from defect detection to resolution
118
119```
120Defect Age = Detection Date - Introduction Date
121Resolution Time = Resolution Date - Detection Date
122Target: < 7 days for critical defects
123```
124
125### Defect Severity Distribution
126- **Critical**: System failure, data loss
127- **High**: Major functionality broken
128- **Medium**: Minor functionality broken
129- **Low**: Cosmetic issues, typos
130
131### Defect Trend Analysis
132- Track defects over time
133- Identify patterns and trends
134- Correlate with code changes
135- Predict future defect rates
136
137## Quality Gates and Acceptance Criteria
138
139### Quality Gate Examples
140```
141Code Quality Gate:
142- Code coverage ≥ 80%
143- No critical or high severity defects
144- Cyclomatic complexity ≤ 10
145- No security vulnerabilities
146- All tests passing
147
148Performance Gate:
149- p95 response time < 500ms
150- Error rate < 0.1%
151- Throughput ≥ 1000 RPS
152- CPU utilization < 70%
153
154Security Gate:
155- No high/critical vulnerabilities
156- OWASP Top 10 compliance
157- Dependency scan clean
158- Authentication/authorization tested
159```
160
161### Acceptance Criteria
162- **Functional Requirements**: All features work as specified
163- **Non-Functional Requirements**: Performance, security, usability met
164- **Test Coverage**: Minimum coverage thresholds met
165- **Defect Standards**: No defects above acceptable severity
166- **Documentation**: All documentation complete and accurate
167
168## Test Reporting and Dashboards
169
170### Test Execution Reports
171- Total tests run
172- Pass/fail counts and percentages
173- Test execution time
174- Flaky test identification
175- Test failure categorization
176
177### Coverage Reports
178- Line, branch, function coverage
179- Coverage by module/component
180- Uncovered code highlighting
181- Coverage trends over time
182- Coverage comparison between branches
183
184### Defect Reports
185- Open defects by severity
186- Defect trends and patterns
187- Defect age distribution
188- Defect resolution time
189- Defect density by module
190
191### Performance Reports
192- Response time metrics (p50, p95, p99)
193- Throughput metrics
194- Error rates
195- Resource utilization
196- Performance trends over time
197
198### Dashboard Elements
199- Overall quality score
200- Test coverage gauge
201- Defect trend chart
202- Performance metrics
203- Build health status
204- Quality gate status
205
206## QA KPIs and Metrics Tracking
207
208### Process Metrics
209- **Test Execution Time**: Time to run test suite
210- **Test Automation Rate**: Percentage of tests automated
211- **Test Case Count**: Total number of test cases
212- **Test Case Execution**: Number of tests executed per period
213- **Defect Detection Rate**: Defects found per testing hour
214
215### Product Metrics
216- **Defect Escape Rate**: Defects found in production
217- **Mean Time to Detection**: Time to find defects
218- **Mean Time to Resolution**: Time to fix defects
219- **Customer Reported Defects**: Defects reported by users
220- **Test Coverage**: Code, feature, and requirement coverage
221
222### Team Metrics
223- **Test Case Productivity**: Test cases created per person-hour
224- **Automation Productivity**: Automated tests created per person-hour
225- **Defect Detection Efficiency**: Defects found per person-hour
226- **Test Execution Efficiency**: Tests executed per person-hour
227
228### Quality Metrics
229- **Overall Quality Score**: Composite quality metric
230- **Test Pass Rate**: Percentage of passing tests
231- **Defect Density**: Defects per size metric
232- **Code Quality Score**: Based on complexity, duplication, smells
233- **Performance Score**: Based on response time, throughput, errors
234
235### Metrics Dashboard
236```
237Quality Dashboard:
238┌─────────────────────────────────────────┐
239│ Overall Quality Score: 87/100 │
240├─────────────────────────────────────────┤
241│ Test Coverage: 85% │
242│ ├─ Line: 87% │
243│ ├─ Branch: 82% │
244│ └─ Function: 90% │
245├─────────────────────────────────────────┤
246│ Code Quality: 82/100 │
247│ ├─ Complexity: 8.2 avg │
248│ ├─ Duplication: 3.1% │
249│ └─ Maintainability: 78 │
250├─────────────────────────────────────────┤
251│ Defects: 12 open │
252│ ├─ Critical: 1 │
253│ ├─ High: 3 │
254│ ├─ Medium: 5 │
255│ └─ Low: 3 │
256├─────────────────────────────────────────┤
257│ Performance: 92/100 │
258│ ├─ p95 Response: 420ms │
259│ ├─ Throughput: 1250 RPS │
260│ └─ Error Rate: 0.05% │
261└─────────────────────────────────────────┘
262```
263
264## Metrics Collection and Analysis
265
266### Data Collection
267- Automated collection from CI/CD pipelines
268- Integration with test frameworks
269- Real-time monitoring and alerts
270- Historical data storage
271- Data normalization and aggregation
272
273### Analysis Techniques
274- Trend analysis over time
275- Comparison between branches/releases
276- Correlation with code changes
277- Root cause analysis of quality issues
278- Predictive analytics for quality forecasting
279
280### Reporting Frequency
281- **Real-time**: Build status, test failures, critical defects
282- **Daily**: Test execution, defect updates, performance metrics
283- **Weekly**: Quality trends, coverage reports, team metrics
284- **Monthly**: Quality scorecards, process improvements, strategic insights
285- **Quarterly**: Quality reviews, goal setting, process optimization
286
287### Continuous Improvement
288- Identify quality trends and patterns
289- Set quality goals and targets
290- Track progress toward goals
291- Implement process improvements based on metrics
292- Celebrate quality achievements