← VCE Software Development U3O1

Testing one module in isolation

Testing one function or class on its own, with its own test table, before joining it to the rest of the program, so a failing test points to that module.

Understanding Testing one module in isolation in VCE Software Development U3O1

What it does: The function is called alone with one fixed input, and the expected output is written next to it, so a failure points straight to is_adult(). Re-testing means running the same test case on the same module after the fix. If it passes now, the fix worked. Isolated testing narrows the search for the fault to a single function or class. Testing the combined solution is still needed later. Testing a class method on its own means creating an object of that class and calling just that method, with no other parts of the program involved. Because only that function was run, a failing test points to it. This is the main benefit of unit testing.

Common mistakes: A test compares the actual result with the expected result, so it needs the comparison operator ==. A single = is assignment and causes a syntax error. It should be assert double(4) == 8. The boundary test is_adult(18) expects True, but age > 18 returns False for 18. The failing test points straight to this function. It should be return age >= 18.

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 178–193) 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
Which approach tests a function in isolation?
Run the whole program and hope the function gets usedCall the function on its own with fixed inputs and compare the result to the expected output
Matches
result = main() assert result == 25
↓
This runs the whole program through main() instead of calling the one function under test, so a failure could come from any module.
Applying
Meanings
Term
unit testing
Meaning
Testing one function or class on its own, with its own test table, before joining it to the rest of the program, so a failing test points to that module.
Practice
def calc_total(price, qty):
Testing
Gaps
assert (4) == 8
Check Answer
Spots
2 return n * 2
3assert double(4) = 8

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

The 'Space Turtle' badge — Speed in Zero-G, 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. Which approach tests a function in isolation?
A. Call the function on its own with fixed inputs and compare the result to the expected output ✓
B. Run the whole program and hope the function gets used
Testing in isolation means running just that one function with chosen inputs, so any failure points straight to it.
2. Why do we test one module on its own before joining it to the rest of the solution?
A. It lets us skip testing once the modules are joined
B. A failing test points to that module, so the fault is easy to find ✓
Isolated testing narrows the search for the fault to a single function or class. Testing the combined solution is still needed later.
3. A function calculate_gst(price) is tested with price = 100 and the expected output is 10. What goes in the test table?
A. Input: calculate_gst, Expected: 100, Actual: 10
B. Input: 100, Expected: 10, Actual: the value the function returns ✓
A test table lists the input given to the module, the expected output and the actual output returned by the module.
4. Which test is an isolated test of a class method?
A. Create one Student object, call its get_grade() method and check the result ✓
B. Start the whole GUI, enter data and click through every screen
Testing a class method on its own means creating an object of that class and calling just that method, with no other parts of the program involved.
5. A test of a function in isolation fails. Where is the fault most likely to be?
A. Inside that function ✓
B. In another module that has not been written yet
Because only that function was run, a failing test points to it. This is the main benefit of unit testing.

Match the Pairs

assert calc_gst(100) == 10 → Tests the calc_gst() function alone with a fixed input of 100 and checks it returns the expected 10
acct.deposit(50) assert acct.balance == 150 → Tests one class method on its own by calling it, then checking the object's state matches the expected value
Test a function by itself using a fixed input and a known expected output before joining it to the main program → assert is_adult(18) == True
After fixing a faulty function, run the same test again to confirm the fix works and has not broken anything → assert average([2, 4, 6]) == 4
result = main() assert result == 25 → This runs the whole program through main() instead of calling the one function under test, so a failure could come from any module.
def total(a, b): return a - b assert total(2, 3) == 5 # fixed, so no need to re-test → The code was changed but the test was not run again, so there is no evidence the fix works or that it has not caused new errors.

Key Term

unit testing
Testing one function or class on its own, with its own test table, before joining it to the rest of the program, so a failing test points to that module.

Fill in the Blanks

1. def double(n): return n * 2 assert double(4) == 8
Hint: Type the name of the function being tested on its own with a fixed input.
2. def area(w, h): return w * h assert area(3, 4) == 12
Hint: Type the operator that checks the actual result equals the expected result.
3. acc = Account(100) acc.withdraw(30) assert acc.balance == 70
Hint: Type the name of the class method being tested, the one that lowers the balance.
4. def adult(age): return age >= 18 assert adult(18) == True
Hint: Type the Boolean expected result when re-testing the fixed function at the boundary value.
5. def cube(n): return n ** 3 assert cube(2) == 8
Hint: Type the keyword that checks a test and raises an error if the result is wrong.

Spot the Error

Question 1
A def double(n):
B return n * 2
C assert double(4) = 8
Line C — A test compares the actual result with the expected result, so it needs the comparison operator ==. A single = is assignment and causes a syntax error. It should be assert double(4) == 8.
Question 2
A def is_adult(age):
B return age > 18
C assert is_adult(18) == True
D assert is_adult(17) == False
Line B — The boundary test is_adult(18) expects True, but age > 18 returns False for 18. The failing test points straight to this function. It should be return age >= 18.
Question 3
A def add(a, b)
B return a + b
C assert add(2, 3) == 5
Line A — The function header is missing its colon, so the module cannot be loaded and tested. It should be def add(a, b):.
Question 4
A c = Counter
B c.add()
C assert c.count == 1
D print('Counter test passed')
Line A — Without brackets, c refers to the class itself and no object is created, so c.add() cannot test the method. It should be c = Counter() to create an instance.
Question 5
A def total(price, qty):
B return price * qty
C assert total(5, 3) == 8
Line C — The expected value in a test table must come from the requirement, not from a guess. 5 * 3 should give 15, so this test would fail even though the function is correct. It should be == 15.

Student with a class code? Join your class →