0
0
Testing Fundamentalstesting~10 mins

Test metrics and KPIs in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the system correctly calculates and displays key test metrics and KPIs such as test pass rate, defect density, and test execution progress.

Test Code - unittest
Testing Fundamentals
import unittest

class TestMetricsKPIs(unittest.TestCase):
    def setUp(self):
        # Simulate test results data
        self.total_tests = 100
        self.passed_tests = 85
        self.failed_tests = 15
        self.total_defects = 10
        self.lines_of_code = 5000

    def test_pass_rate(self):
        pass_rate = (self.passed_tests / self.total_tests) * 100
        self.assertAlmostEqual(pass_rate, 85.0, places=1)

    def test_defect_density(self):
        defect_density = self.total_defects / (self.lines_of_code / 1000)
        self.assertAlmostEqual(defect_density, 2.0, places=1)

    def test_execution_progress(self):
        executed_tests = self.passed_tests + self.failed_tests
        progress = (executed_tests / self.total_tests) * 100
        self.assertEqual(progress, 100)

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test suite starts and test data is set up with total tests, passed tests, failed tests, defects, and lines of code.Test environment initialized with simulated test metrics data.-PASS
2Calculate pass rate as (passed_tests / total_tests) * 100.Pass rate calculated as 85%.Assert pass rate equals 85.0 within 1 decimal place.PASS
3Calculate defect density as total_defects divided by (lines_of_code / 1000).Defect density calculated as 2.0 defects per KLOC.Assert defect density equals 2.0 within 1 decimal place.PASS
4Calculate test execution progress as (executed_tests / total_tests) * 100.Execution progress calculated as 100%.Assert execution progress equals 100%.PASS
5Test suite completes all tests successfully.All assertions passed, test metrics verified.-PASS
Failure Scenario
Failing Condition: If the calculated pass rate, defect density, or execution progress does not match expected values.
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify when calculating pass rate?
AThe total number of tests executed
BThe percentage of tests that passed out of total tests
CThe number of defects found per thousand lines of code
DThe time taken to execute all tests
Key Result
Always verify that test metrics calculations use correct formulas and data inputs to ensure accurate reporting of test progress and quality.