GCSE · Computer Science · Edexcel · Spec 1CP2
Identifying and correcting program errors
Your program runs. No red text, no crash. So it must be right... mustn't it? Let's see how a test catches a bug no error message mentions.
Computer Science · Testing and debugging
Test 3 fails: follow the bug
A made-up bike-hire program. Test table row: Test 3 · negative number of days · input -3 · expected output Rejected. The output box keeps everything printed so far, so you can see both runs.
The hire shop only hires bikes for 1 to 14 days. Before you press Next: what should the program do with -3?
1 # Version 1: the first attempt2 days = int(input("Days: "))3 print("Cost: £" + str(days * 5))4 # Version 2: after debugging5 days = int(input("Days: "))6 if days < 1 or days > 14:7 print("Rejected")8 else:9 print("Cost: £" + str(days * 5))
Variables
Output
Step 1: Test 3 from the test table: the input is -3 days, and the expected output is Rejected. Line 1 reads the input, so days now holds -3.
Press Next to move one step at a time. The chips show the test row: days is the input, then expected, actual and the result.
Choosing test data
Normal, boundary or erroneous?
The bike-hire program should accept a whole number of days from 1 to 14. Pick a test value, then pick the kind of test data it is.
Still to sort
Normal (0)
Valid data that should be accepted.
Where the line is: Normal data is valid and not on an edge. Edge values are boundary data, even though some are accepted.
Boundary (0)
On the edge of being valid: on or just inside is accepted, just outside is rejected.
Where the line is: Boundary data sits on the edge. A word typed instead of a number is erroneous, not boundary.
Erroneous (0)
Data that should not be accepted because it would cause an error.
Where the line is: Erroneous data is the wrong kind of thing, such as a string where an integer is required. A number just outside the range is boundary data.
Predict, then check
Two modules, each tested and each passing. Commit before you look.
Two modules were written separately and each passed all of its own tests. They are now joined into one program. Which is true?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
A program can run perfectly and still be wrong. Here's how a test catches it and how you fix it.
What you need to know
- A bug is an error in code that stops it working as expected; debugging is finding and correcting errors.
- Testing is the systematic process of checking that a program works as expected, and it is how errors are identified.
- Syntax errors break the rules of the language. The translator flags them, so the program will not run.
- Logic errors let the program run but give an unexpected result, and the IDE cannot pick them up.
- Runtime errors happen when the program is run: the code is valid and logical, but the input or environment causes the error.
Have a goSam says: 'My program printed no error message, so it must be perfect.' Which of the three error types could Sam still have?
Two of them: a logic error, or a runtime error. Only a syntax error is ruled out.
A syntax error would stop the program running. A logic error runs to the end with a wrong result the IDE cannot pick up. A runtime error only appears with certain input or environments, so this run may have missed it.
- To debug: find the error, read the message, trace the code to where it occurs, fix it, then run it again to check.
- A test table records the test number, description, input data, expected output, actual output and, if the test failed, how it was fixed.
Have a goIn a test, the expected output is 15 and the actual output is 15. Which test table column can stay empty for that test?
The 'how it was fixed' column.
That column is only filled in if the test failed. A passing test has nothing to fix, though its actual output is still recorded.
- Normal data is valid and should be accepted; erroneous data should not be accepted, like a string where an integer is needed.
- Boundary data sits on the edge of valid: on or just inside gets accepted, just outside gets rejected.
Have a goAn age box accepts whole numbers from 13 to 17. A tester tries 15 and 18. Which is boundary data, and should it be accepted?
18: it is just outside the edge, so it should be rejected.
15 is normal data, valid and nowhere near an edge. Boundary data sits on the edge, and values just outside it should be rejected.
- Iterative testing checks each section as it is written; integration testing checks that separately tested modules work together.
The big picture
A bug is an error in code, and 'it ran without an error message' does not mean 'it is correct'. Testing compares the expected output with the actual output, using normal, boundary and erroneous data. When they differ you debug: trace the code, fix the error, then run the test again. Syntax, logic and runtime errors behave differently, and testing goes on throughout development, section by section and again when modules are combined.
Key points
Worked example
Problem
A short program should print the total of the numbers 1 to 5. In the test table, Test 1 has expected output 15 and actual output 10. The code is: total = 0, then for number in range(1, 5): total = total + number, then print(total). Find the error, fix it and prove the fix works.
⚠ Watch out
Thinking that a program with no error message must be correct. A logic error gives no message at all, and a runtime error only appears with certain input or environments. Only comparing actual output with expected output, across normal, boundary and erroneous data, shows you what your program really does.
Memory hook
Expected, Actual, Trace, Fix, Retest: if the first two differ, trace the code, fix the cause, then run the same test again.
Check yourself
A program runs to the end with no error message but prints the wrong total. Name the error type, say why the IDE missed it, and list what you would do next.
Flashcards
(14)What is a bug?
What is debugging?
What is testing?
What is a syntax error?
What is a logic error?
What is a runtime error?
Which logic error causes does this lesson name?
What are the steps of debugging?
What does a test table record?
What is normal test data?
What is boundary test data?
What is erroneous test data?
What is iterative testing?
What is integration testing?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore Edexcel GCSE Computer Science topics
- Converting algorithms to programs
- CSV file I/O
- Decomposition and abstraction in programming
- Evaluating program fitness and efficiency
- Functions vs procedures
- Global vs local variables
- Primitive data types
- Programming – condition-controlled repetition
- Programming – count-controlled repetition
- Programming – iteration over data structures
- Programming – selection
- Programming – sequencing
How this lesson was checked. This Edexcel GCSE Computer Science (specification 1CP2)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 21 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.