Test Overview
This test checks if the defect metrics calculation feature correctly counts and reports the number of defects found during testing. It verifies that the system accurately tracks defects by severity and status.
This test checks if the defect metrics calculation feature correctly counts and reports the number of defects found during testing. It verifies that the system accurately tracks defects by severity and status.
import unittest class DefectMetrics: def __init__(self): self.defects = [] def add_defect(self, defect): self.defects.append(defect) def count_defects(self, severity=None, status=None): return len([ d for d in self.defects if (severity is None or d['severity'] == severity) and (status is None or d['status'] == status) ]) class TestDefectMetrics(unittest.TestCase): def setUp(self): self.metrics = DefectMetrics() self.metrics.add_defect({'id': 1, 'severity': 'High', 'status': 'Open'}) self.metrics.add_defect({'id': 2, 'severity': 'Low', 'status': 'Closed'}) self.metrics.add_defect({'id': 3, 'severity': 'Medium', 'status': 'Open'}) def test_count_all_defects(self): total = self.metrics.count_defects() self.assertEqual(total, 3) def test_count_open_defects(self): open_defects = self.metrics.count_defects(status='Open') self.assertEqual(open_defects, 2) def test_count_high_severity_defects(self): high_severity = self.metrics.count_defects(severity='High') self.assertEqual(high_severity, 1) if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts - unittest framework initializes TestDefectMetrics | Test environment ready with DefectMetrics class and test data | - | PASS |
| 2 | setUp method runs - adds three defects with different severities and statuses | DefectMetrics instance contains 3 defects: High/Open, Low/Closed, Medium/Open | - | PASS |
| 3 | test_count_all_defects runs - counts all defects without filters | Counting defects in DefectMetrics | Assert total defects count equals 3 | PASS |
| 4 | test_count_open_defects runs - counts defects with status 'Open' | Counting defects with status 'Open' | Assert open defects count equals 2 | PASS |
| 5 | test_count_high_severity_defects runs - counts defects with severity 'High' | Counting defects with severity 'High' | Assert high severity defects count equals 1 | PASS |
| 6 | All tests complete | All assertions passed, test suite finished successfully | - | PASS |