Testing a function with expected and actual output
Test a function by calling it with chosen inputs, logging the actual result next to the expected value, then recording pass or fail. Retest after any fix.
Understanding Testing a function with expected and actual output in ACARA Digital Technologies Years 7–8
What it does: 6 is a typical input, and the log shows the expected value 36 next to what square(6) really returns. Retesting means calling the function with the same input after the fix and checking that actual now matches expected. If you copy the output as the expected value, the test always passes, even when the function is wrong. Boundary inputs sit right at the edge where the behaviour changes, so that is where bugs often hide. Add a normal input too. A fix can accidentally break something that used to work, so retest every case. The second line only prints the number 16 and never calls square(), so it tests nothing.
Common mistakes: sq has no brackets or input, so the function is not called. The test prints the function itself, not the actual result. It should be sq(5). Squaring means multiplying n by itself. With n + n, sq(5) gives 10, so the test would show 10 next to the expected 25 and fail. It should be return n * n;.
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 624–634) and word search (Modules 611–634).
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
console.log("expected 25, got", square(5))Fill in the Blanks
Spot the Error
Student with a class code? Join your class →