0
0
Testing Fundamentalstesting~10 mins

Cost of bugs at different stages in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test simulates finding a bug at different stages of software development and verifies the cost impact at each stage.

It checks that bugs found earlier cost less to fix than those found later.

Test Code - unittest
Testing Fundamentals
import unittest

class TestBugCost(unittest.TestCase):
    def cost_of_bug(self, stage):
        costs = {
            'requirements': 100,
            'design': 500,
            'coding': 1000,
            'testing': 5000,
            'production': 10000
        }
        return costs.get(stage, 0)

    def test_bug_costs(self):
        # Bug found at requirements stage
        cost_req = self.cost_of_bug('requirements')
        self.assertEqual(cost_req, 100)

        # Bug found at design stage
        cost_des = self.cost_of_bug('design')
        self.assertEqual(cost_des, 500)

        # Bug found at coding stage
        cost_code = self.cost_of_bug('coding')
        self.assertEqual(cost_code, 1000)

        # Bug found at testing stage
        cost_test = self.cost_of_bug('testing')
        self.assertEqual(cost_test, 5000)

        # Bug found at production stage
        cost_prod = self.cost_of_bug('production')
        self.assertEqual(cost_prod, 10000)

        # Verify costs increase with later stages
        self.assertTrue(cost_req < cost_des < cost_code < cost_test < cost_prod)

if __name__ == '__main__':
    unittest.main()
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test startsTest framework initialized, test class loaded-PASS
2Calls cost_of_bug('requirements')Returns 100assertEqual(100, 100)PASS
3Calls cost_of_bug('design')Returns 500assertEqual(500, 500)PASS
4Calls cost_of_bug('coding')Returns 1000assertEqual(1000, 1000)PASS
5Calls cost_of_bug('testing')Returns 5000assertEqual(5000, 5000)PASS
6Calls cost_of_bug('production')Returns 10000assertEqual(10000, 10000)PASS
7Checks costs increase with later stagesValues: 100 < 500 < 1000 < 5000 < 10000assertTrue(cost_req < cost_des < cost_code < cost_test < cost_prod)PASS
8Test endsAll assertions passed-PASS
Failure Scenario
Failing Condition: If cost values do not match expected or order is incorrect
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify about bug costs?
ABugs cost less to fix the later they are found
BBugs cost the same at all stages
CBugs cost more to fix the later they are found
DBug cost is random
Key Result
Testing cost impact at different stages helps teams understand why early bug detection saves money and effort.