0
0
Testing Fundamentalstesting~10 mins

Defect metrics in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - unittest
Testing Fundamentals
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()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts - unittest framework initializes TestDefectMetricsTest environment ready with DefectMetrics class and test data-PASS
2setUp method runs - adds three defects with different severities and statusesDefectMetrics instance contains 3 defects: High/Open, Low/Closed, Medium/Open-PASS
3test_count_all_defects runs - counts all defects without filtersCounting defects in DefectMetricsAssert total defects count equals 3PASS
4test_count_open_defects runs - counts defects with status 'Open'Counting defects with status 'Open'Assert open defects count equals 2PASS
5test_count_high_severity_defects runs - counts defects with severity 'High'Counting defects with severity 'High'Assert high severity defects count equals 1PASS
6All tests completeAll assertions passed, test suite finished successfully-PASS
Failure Scenario
Failing Condition: The count_defects method returns incorrect counts due to filtering logic error
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test_count_open_defects verify?
AIt verifies the number of defects with status 'Open' is counted correctly
BIt verifies the total number of defects regardless of status
CIt verifies the number of defects with severity 'High'
DIt verifies the defects are added to the list
Key Result
Always verify that your filtering logic in defect metrics calculations correctly matches the criteria to avoid incorrect defect counts.