2.3.2 Testing · Paper 2
Testing: finding and fixing errors
Each section has pictures and things to try, then its key points and key words. Exam practice is at the end of the page.
You need to know
- Why we test programs
- Iterative testing and final (terminal) testing
- Syntax and logic errors
- Normal, boundary, invalid and erroneous test data, and choosing test data for a scenario
- Creating and completing a test plan
- Refining algorithms
You don't need to know
- OCR doesn't rule anything out here.
Why and when we test
Testing finds errors and checks the program does what it should, before users find problems.
Two kinds of error:
Try it
Iterative or final testing?
- Testing the login procedure as soon as it is written
- Testing the whole app before it is released
- Fixing a bug, then testing that part again
- Checking the finished game meets every requirement
Try it
Syntax error or logic error?
- pritn("Hello")
- if score > 50 then, when 50 should pass
- print("Hello"
- total = total - price in a program that adds up prices
- A for loop with no next i
- average = a + b / 2
Key points
Why we test
- Testing finds errors so they can be fixed before users find them.
- It checks the program does what it should (meets the requirements).
- It checks the program doesn't crash when given unexpected input.
- Good testing uses a plan with lots of different test data.
Iterative and final testing
Before this: Why we test
- Iterative testing happens while the program is being written. Each part is tested, fixed, and tested again.
- Final (terminal) testing happens at the end. The whole program is tested to check it all works together and meets the requirements.
- Most programs need both.
Syntax and logic errors
- A syntax error breaks the rules of the language, so the program won't run.
- Examples: a missing bracket, pritn instead of print, or a missing endif.
- A logic error means the program runs but gives the wrong result.
- Examples: > instead of >=, adding instead of multiplying, or a loop running one time too few.
- The IDE finds syntax errors for you. Logic errors are found by testing and trace tables.
Key words
Say what each one means, then tap to check.
Test data
Example: a program accepts ages from 11 to 16.
Should be accepted
On the very edge of valid
Right type, should be rejected
Wrong type, should be rejected
Try it
A program accepts whole numbers from 1 to 10. What type of test data is each one?
- 5
- 1
- 15
- "five"
- 10
- 7.5
- -4
Key points
Normal, boundary, invalid and erroneous data
Before this: 2.3.1Input validation
- Normal: sensible data that should be accepted.
- Boundary: data on the very edge of what is allowed.
- Invalid: the right data type, but outside the allowed range. It should be rejected.
- Erroneous: the wrong data type completely. It should be rejected.
- Example: a program accepts ages 11 to 16. Normal 13, boundary 11 or 16, invalid 25, erroneous "ten".
Key words
Say what each one means, then tap to check.
Test plans
| Test | Data | Type | Expected result | Actual result |
|---|---|---|---|---|
| 1 | 13 | Normal | Accepted | Accepted ✓ |
| 2 | 16 | Boundary | Accepted | Rejected ✗ |
| 3 | "ten" | Erroneous | Error message | Error message ✓ |
Try it
Run the test plan. Then refine the program until every test passes.
Key points
Test plans
Before this: Normal, boundary, invalid and erroneous data
- A test plan lists each test before it is carried out.
- Each row has: what is being tested, the test data, the type of data, and the expected result.
- When the test is run, the actual result is filled in.
- If the actual result doesn't match the expected result, there's an error to fix.
Example: a program accepts ages from 11 to 16.
| Test | What is tested | Test data | Type | Expected result |
|---|---|---|---|---|
| 1 | Age in range | 13 | Normal | Accepted |
| 2 | Lowest allowed age | 11 | Boundary | Accepted |
| 3 | Age too high | 25 | Invalid | Error message |
| 4 | Not a number | ten | Erroneous | Error message |
Refining algorithms
Before this: Test plans
- Refining means improving an algorithm after testing.
- Fix errors that testing found, then test again.
- Make it cope with unexpected input, e.g. add validation.
- Make it more efficient or easier to read.
Key words
Say what each one means, then tap to check.
Exam practice
14 questions in the style of the OCR exam, 34 marks in total. Try each one, then check the mark scheme.
Why and when we test
Hint
Think about bugs, what the program is meant to do, and what happens if someone types something odd.
Give means give a short, clear answer. You don't need to explain it.
2 marks: make 2 separate points.
Show mark scheme
- To find and fix errors / bugs.
- To check it meets the requirements / does what it should.
- To make sure it doesn't crash with unexpected input.
1 mark for each, up to 2.
Hint
When does each one happen, and how much of the program does it test?
Describe means say what it is like or what happens. Make each point a separate fact.
2 marks: make 2 separate points.
Show mark scheme
- Iterative testing is done during development, on each part / after each change.
- Final testing is done at the end, on the whole program.
1 mark for each.
Hint
If every part works on its own, does that prove they all work together?
Explain means say what happens and why. Words like “because” and “so” help.
2 marks: aim for 2 things said, such as a point and then the reason for it.
Show mark scheme
- Parts may work alone but not together…
- …so the whole program needs checking against the requirements.
1 mark for each point.
Hint
One of them is caught by the translator. The other one the computer can't spot. Why not?
Describe means say what it is like or what happens. Make each point a separate fact.
2 marks: make 2 separate points.
Show mark scheme
- A syntax error breaks the rules of the language / stops the program running.
- A logic error lets the program run but gives the wrong output.
Don't accept: "A logic error crashes the program". A logic error lets the program run but gives the wrong result.
1 mark for each.
- print("Hello"
- if score > 50 then, when a score of 50 should count as a pass
Hint
Would line a run at all? Would line b run, but give the wrong result for 50?
State means give a short, clear answer. You don't need to explain it.
2 marks: make 2 separate points.
Show mark scheme
- a) Syntax error (the closing bracket is missing).
- b) Logic error (it should be >=).
1 mark for each.
Test data
- Normal
- Boundary
- Invalid
- Erroneous
Hint
Normal is safely inside the range and boundary is right on the edge. Invalid is the right type but out of range. Erroneous is the wrong type.
Give means give a short, clear answer. You don't need to explain it.
4 marks: make 4 separate points.
Show mark scheme
- a) Normal: any whole number from 2 to 7.
- b) Boundary: 1 or 8.
- c) Invalid: a number outside 1 to 8, e.g. 0 or 12.
- d) Erroneous: not a whole number, e.g. "two" or 3.5.
Also accept: 0 or 9 as boundary data. Some mark schemes count the values just outside the range too.
1 mark for each.
Hint
Where do mistakes like < instead of <= show up?
Explain means say what happens and why. Words like “because” and “so” help.
1 mark: one point, with the reason.
Show mark scheme
- Logic errors often happen at the edges, e.g. < used instead of <=.
Test plans
Hint
Choose a value for each type of test data. Then say whether the program should accept it or show an error.
Complete means fill in every gap.
3 marks: check every part before you finish.
Show mark scheme
- Normal, e.g. 55: accepted.
- Boundary, e.g. 0 or 100: accepted.
- Erroneous, e.g. "fifty": rejected / error message.
Also accept: Boundary data just outside the range, e.g. 101, if the expected result is rejected.
Don't accept: Erroneous: 150. That is the right data type but out of range, so it is invalid, not erroneous.
1 mark for each row with the test data and expected result.
Hint
Once you know there is an error, what do you do about it? And then what?
State means give a short, clear answer. You don't need to explain it.
1 mark: one answer is enough.
Show mark scheme
- The error is found and fixed, then the test is run again.
Also accept: The algorithm is refined / debugged and retested.
bill = float(input("Total bill")) people = int(input("How many people?")) print(bill / people)
Hint
Add a while loop after the people input. Keep asking while people is 0 or less.
Refine means improve the code so it does what is asked. Keep everything else working.
3 marks: each part that works earns marks, even if the whole thing isn't perfect.
Show mark scheme
- Loop while people is 0 or less.
- Ask for the number of people again inside the loop.
- Division only happens after valid input.
Don't accept: if people == 0 on its own. It only asks again once.
Example answer
bill = float(input("Total bill")) people = int(input("How many people?")) while people <= 0 people = int(input("Must be 1 or more")) endwhile print(bill / people)
1 mark for each point. Python is fine too.
Mixed questions on the whole page
- A programmer tests the login procedure as soon as they finish writing it.
- Before the app is released, the whole app is tested to check it meets all its requirements.
Hint
Is it during development on one part, or at the end on everything?
State means give a short, clear answer. You don't need to explain it.
2 marks: make 2 separate points.
Show mark scheme
- a) Iterative testing
- b) Final / terminal testing
1 mark for each.
| Test data | Type of test data | Expected result |
|---|---|---|
| 25 | ||
| 0 | ||
| 75 | ||
| "abc" |
Hint
Is the value in the middle of 0 to 50, on the edge, outside it, or not a number at all? Then decide if it should be accepted.
Complete means fill in every gap.
4 marks: check every part before you finish.
Show mark scheme
- 25: Normal, accepted.
- 0: Boundary, accepted.
- 75: Invalid, rejected / error message.
- "abc": Erroneous, rejected / error message.
Don't accept: 75 as "erroneous". It is the right data type but outside the range, so it is invalid.
1 mark for each row with both parts correct.
score = int(input("Score")) if score > 40 then print("Pass") else pritn("Fail") endif
Hint
One line breaks the rules of the language. For the other, try a score of exactly 40. Does it pass?
Identify means pick out or name the right thing. A short answer is enough.
4 marks: make 4 separate points.
Show mark scheme
- Syntax error: line 5, pritn…
- …should be print.
- Logic error: line 2, > means a score of 40 fails…
- …so it should be >=.
Also accept: No line numbers, as long as each error is clearly identified.
Also accept: Logic fix: score > 39.
Don't accept: Saying the else or endif lines are wrong. Those lines are correct.
1 mark for each error, 1 mark for each fix.
Hint
Normal data might all work fine. What could still go wrong with the edge values, or with silly inputs?
Explain means say what happens and why. Words like “because” and “so” help.
2 marks: aim for 2 things said, such as a point and then the reason for it.
Show mark scheme
- Errors often happen at the edges of the range, e.g. < used instead of <=, which only boundary data finds.
- Invalid or erroneous data might not be rejected, or might make the program crash.
1 mark for each point.