Beginner level · Module 5: Python Beginner Project Studio · Lesson 2 of 3
Testing by Hand and Debugging
Design test cases, including bad input, and use print debugging and the editor's debugger to find faults.
In this lesson you will
- Write a table of test cases with expected results
- Find a bug using print statements or breakpoints
Key concepts
test caseexpected vs actualedge casebreakpoint
The lesson
Testing means checking that the program does what the requirements say, including the awkward cases. A test table lists each input, the expected output and the actual output; a mismatch is a bug to investigate.
When you find a bug, reproduce it first, then narrow it down. Adding print() lines that show variable values at key points is a simple and effective debugging technique; Thonny's debugger lets you step through the program line by line and watch the variables change.
After fixing a bug, re-run all your tests, not only the one that failed. Fixes sometimes break something else.
Step by step
- Write at least five test cases, including empty and non-numeric input.
- Run each case and record the actual output.
- Investigate one mismatch with print() or the debugger.
- Fix it and re-run the whole table.
Practice activity
Create a test table with at least five cases (including empty and non-numeric input) and record the results for your project.
Expected result: A completed test table and at least one bug found and fixed with evidence.
Check your understanding
-
Why decide the expected result before running a test?
Show answer
So you judge the program against the requirement, not against whatever it happens to output.
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.