Test Overview
This test checks the difference between testing and debugging by simulating a simple test that finds a bug and then the debugging step to fix it. It verifies that testing detects the problem and debugging resolves it.
This test checks the difference between testing and debugging by simulating a simple test that finds a bug and then the debugging step to fix it. It verifies that testing detects the problem and debugging resolves it.
import unittest class Calculator: def add(self, a, b): return a + b def subtract(self, a, b): # Bug: mistakenly adds instead of subtracting return a + b class TestCalculator(unittest.TestCase): def test_subtract(self): calc = Calculator() result = calc.subtract(5, 3) self.assertEqual(result, 2, "Subtract method should return difference") if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts by importing unittest and defining Calculator class with add and subtract methods | Code loaded in memory, no errors yet | - | PASS |
| 2 | Test case TestCalculator.test_subtract is executed | Calculator instance created, subtract method called with (5,3) | Check if subtract(5,3) equals 2 | FAIL |
| 3 | Test framework reports failure because subtract returned 8 instead of 2 | Test report shows failure with message 'Subtract method should return difference' | AssertionError: 8 != 2 | FAIL |
| 4 | Developer starts debugging by inspecting subtract method code | Code shows subtract method incorrectly adds instead of subtracting | - | PASS |
| 5 | Developer fixes subtract method to return a - b | Code updated, subtract method now correct | - | PASS |
| 6 | Test case re-run after fix | subtract(5,3) returns 2 as expected | Check if subtract(5,3) equals 2 | PASS |
| 7 | Test framework reports test passed | Test report shows all tests passed | - | PASS |