Python · Beginner level

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

  1. Write at least five test cases, including empty and non-numeric input.
  2. Run each case and record the actual output.
  3. Investigate one mismatch with print() or the debugger.
  4. 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

  1. 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.