Writing test cases before the code
Write test cases and expected results from the requirements before coding, so they check what the program should do, not what your code does. Rerun them as it grows.
Understanding Writing test cases before the code in ACARA Digital Technologies Years 9–10
What it does: The expected value is worked out from the stated discount rule, so it does not depend on the code you wrote. The loop runs all saved test cases against the function each time, so old features are rechecked after every new change. Test cases written from the requirements check what the program should do. Waiting until the code is finished makes it tempting to copy whatever the code outputs. The expected result comes from the requirement (12 is under 13, so it is rejected), not from running the program. The tests will always pass, but that proves nothing. A wrong answer in the code becomes a wrong 'expected' result.
Common mistakes: The expected value must come from the requirement. A 10% discount on 200 gives 180, not 200. The test should read assert price(200) == 180. The rule says age 13 or over is allowed, so the boundary value 13 must expect True. The test should be (13, True).
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 591–622) and word search (Modules 536–622).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
test firstFill in the Blanks
Spot the Error
Student with a class code? Join your class →