← VCE Software Development U3O1

Testing a Python program with test cases

A chosen input paired with the output you expect. Run the program with it, compare the real output to the expected result in your test table, then record pass or fail.

Understanding Testing a Python program with test cases in VCE Software Development U3O1

What it does: Two different inputs make the program go down both branches, so each branch gets tested. Boundary values sit on either side of the cut-off in a condition like score >= 50, where mistakes with > and >= often hide. A test case has an input and an expected output. You run the program, compare, then record the result. You never change the expected output to fit. At the boundary value 50, > and >= give different results. 75 gives the same result for both, so it would not reveal the mistake. Testing a single input leaves the else branch untested, so a bug there would be missed.

Common mistakes: A single = assigns a value. To compare the real result with the expected result you need ==, so it should be: if result == expected:. An if line must end with a colon. It should be: if mark >= 50:.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 168–177) and word search (Modules 168–193).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
A test table lists the input 15 and the expected output 'Pass'. What should you do with it?
Change 'Pass' in the table to match whatever the program printsRun the program with 15 and compare the real output to 'Pass'
Matches
Test table: input 80, expected output: (blank)
↓
No expected result was written. Without it you cannot compare the real output and decide pass or fail.
Applying
Meanings
Term
test case
Meaning
A chosen input paired with the output you expect. Run the program with it, compare the real output to the expected result in your test table, then record pass or fail.
Practice
def grade(mark):
Testing
Gaps
print(result == )
Check Answer
Spots
2expected = 'Pass'
3if result = expected:

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Walrus' badge — Method Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. A test table lists the input 15 and the expected output 'Pass'. What should you do with it?
A. Change 'Pass' in the table to match whatever the program prints
B. Run the program with 15 and compare the real output to 'Pass' ✓
A test case has an input and an expected output. You run the program, compare, then record the result. You never change the expected output to fit.
2. Your program prints 'Fail' but the test table expected 'Pass'. What do you record?
A. Fail, because the real output does not match the expected result ✓
B. Pass, because the program ran without crashing
A test passes only when the real output matches the expected output. Running without a crash is not enough.
3. Your program has: if score >= 50: print('Pass') else: print('Fail'). Which set of inputs tests every branch?
A. 80 and 20 ✓
B. 80 and 90
80 goes into the if branch and 20 goes into the else branch. 80 and 90 both take the same branch, so the else code is never tested.
4. A program has if, elif and else. How many test cases do you need to test every branch at least once?
A. 1 (one test covers the whole program)
B. 3 (one for each branch) ✓
Each branch only runs for certain inputs, so you need at least one test case that reaches each one.
5. The rule is: if age >= 13 then print('Allowed'). Which is a boundary value test?
A. Testing age 13 (and 12) ✓
B. Testing age 100
Boundary values sit right on the edge of a condition, like 13 and 12. This is where mistakes like using > instead of >= show up.

Match the Pairs

Test 1: input 15, expected 'Pass' → A test case: one chosen input paired with the output you expect, written in your test table before you run the program
Test 2: input 50, expected 'Pass', actual 'Fail' -> FAIL → The real output did not match the expected result, so you record a fail and then look for the bug
Test every branch: choose one input that runs the if part and one that runs the else part → Tests: input 80 -> 'Pass', input 20 -> 'Fail'
Boundary values: test the numbers right on the edge of a condition, such as just below, on and just above 50 → Tests: input 49, input 50, input 51
Test table: input 80, expected output: (blank) → No expected result was written. Without it you cannot compare the real output and decide pass or fail.
Only test: input 90 for if score >= 50 / else → Only one branch is tested. You also need an input such as 10 for the else branch, plus boundary values like 49 and 50.

Key Term

test case
A chosen input paired with the output you expect. Run the program with it, compare the real output to the expected result in your test table, then record pass or fail.

Fill in the Blanks

1. expected = "Pass" result = grade(50) print(result == expected)
Hint: Type the variable that holds the result you expect from your test table.
2. # Pass mark is 50, so test the boundary result = grade(50) print(result)
Hint: Type the boundary value input that sits exactly on the pass mark.
3. if result == expected: print("PASS")
Hint: Type the operator that checks if two values are equal.
4. tests = [49, 50, 51] for t in tests: print(t, grade(t))
Hint: Type the name of the list variable that holds the test inputs.
5. result = grade(49) if result != "Fail": print("FAIL: test did not match")
Hint: Type the operator that checks if the real output is not equal to the expected result.

Spot the Error

Question 1
A result = grade(50)
B expected = 'Pass'
C if result = expected:
D print('PASS')
Line C — A single = assigns a value. To compare the real result with the expected result you need ==, so it should be: if result == expected:
Question 2
A mark = 49
B if mark >= 50
C print('Pass')
D else:
E print('Fail')
Line B — An if line must end with a colon. It should be: if mark >= 50:
Question 3
A expected = 'Fail'
B actual = grade(49)
C print('Result:' actual)
D print('Expected:', expected)
Line C — The items inside print() must be separated by a comma. It should be: print('Result:', actual)
Question 4
A for mark in [0, 49, 50, 100]:
B result = grade(mark)
C print(mark, result)
D print('Tests done'
Line D — The closing bracket is missing, so Python reports a syntax error. It should be: print('Tests done')
Question 5
A tests = [0, 49, 50, 100]
B for t in test:
C print(t, grade(t))
Line B — The list is called tests, but the loop uses test, which doesn't exist and causes a NameError. It should be: for t in tests:

Student with a class code? Join your class →