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.
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.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts | Test framework initialized, test class loaded | - | PASS |
| 2 | Calls cost_of_bug('requirements') | Returns 100 | assertEqual(100, 100) | PASS |
| 3 | Calls cost_of_bug('design') | Returns 500 | assertEqual(500, 500) | PASS |
| 4 | Calls cost_of_bug('coding') | Returns 1000 | assertEqual(1000, 1000) | PASS |
| 5 | Calls cost_of_bug('testing') | Returns 5000 | assertEqual(5000, 5000) | PASS |
| 6 | Calls cost_of_bug('production') | Returns 10000 | assertEqual(10000, 10000) | PASS |
| 7 | Checks costs increase with later stages | Values: 100 < 500 < 1000 < 5000 < 10000 | assertTrue(cost_req < cost_des < cost_code < cost_test < cost_prod) | PASS |
| 8 | Test ends | All assertions passed | - | PASS |