0
0
Testing Fundamentalstesting~10 mins

Testing vs debugging distinction in Testing Fundamentals - Test Execution Compared

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

Test Code - unittest
Testing Fundamentals
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()
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts by importing unittest and defining Calculator class with add and subtract methodsCode loaded in memory, no errors yet-PASS
2Test case TestCalculator.test_subtract is executedCalculator instance created, subtract method called with (5,3)Check if subtract(5,3) equals 2FAIL
3Test framework reports failure because subtract returned 8 instead of 2Test report shows failure with message 'Subtract method should return difference'AssertionError: 8 != 2FAIL
4Developer starts debugging by inspecting subtract method codeCode shows subtract method incorrectly adds instead of subtracting-PASS
5Developer fixes subtract method to return a - bCode updated, subtract method now correct-PASS
6Test case re-run after fixsubtract(5,3) returns 2 as expectedCheck if subtract(5,3) equals 2PASS
7Test framework reports test passedTest report shows all tests passed-PASS
Failure Scenario
Failing Condition: subtract method incorrectly adds numbers instead of subtracting
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test detect in this example?
AA syntax error in the code
BA missing test case
CA bug in the subtract method
DA performance issue
Key Result
Testing helps find problems by checking expected behavior, while debugging is the process of finding and fixing the cause of those problems.