Every topic starts at New. Sign in and your practice counts.
Testing finds faults and debugging removes them. This topic shows how the two practices work together to build correct programs.
This topic teaches how testing detects faults by comparing actual and expected results and how debugging locates, corrects and retests those faults.
Correct programs are built by checking behaviour and then fixing the faults that checking reveals. Testing provides the check, while debugging provides the fix, so the two practices work as one routine.
Testing runs a program or a function with known inputs and compares the actual result with the expected result. A match builds confidence that the behaviour is required, while a mismatch proves that a fault is present somewhere. Testing therefore answers whether a fault exists, not where it lies.
Debugging begins after a failure has been observed. The programmer reproduces the failure with a small input, traces the execution to the faulty statement and corrects it. The corrected program is then tested again to confirm that the failure has gone and that no new failure appears.