MadeByZack
Sign in
Back

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.

Iterative testingTesting each part while you're building it, and fixing as you go.
Final (terminal) testingTesting the whole finished program at the end.

Two kinds of error:

Syntax errorBreaks the language rules, so the program won't run or translate.
Logic errorThe program runs but gives an unexpected result.

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.

Normal13
Should be accepted
Boundary11 or 16
On the very edge of valid
Invalid25
Right type, should be rejected
Erroneous"ten"
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

TestDataTypeExpected resultActual result
113NormalAcceptedAccepted ✓
216BoundaryAcceptedRejected ✗
3"ten"ErroneousError messageError message ✓
Test 2 failed, which shows a logic error (probably < used instead of <=). Fixing it is refining the algorithm.

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.

TestWhat is testedTest dataTypeExpected result
1Age in range13NormalAccepted
2Lowest allowed age11BoundaryAccepted
3Age too high25InvalidError message
4Not a numbertenErroneousError 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

Question 1[2 marks]
Give two reasons why programs are tested.
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.

Question 2[2 marks]
Describe the difference between iterative testing and final testing.
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.

Question 3[2 marks]
Explain why final testing is still needed if iterative testing has been done.
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.

Question 4[2 marks]
Describe the difference between a syntax error and a logic error.
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.

Question 5[2 marks]
State whether each line contains a syntax error or a logic error.
  1. print("Hello"
  2. 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

Question 6[4 marks]
A program accepts a number of tickets from 1 to 8. Give an example of each type of test data.
  1. Normal
  2. Boundary
  3. Invalid
  4. 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.

Question 7[1 mark]
Explain why boundary data is tested.
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

Question 8[3 marks]
A program asks for a percentage from 0 to 100. Complete three rows of a test plan: one normal, one boundary and one erroneous test. Give the test data and expected result for each.
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.

Question 9[1 mark]
State what should happen when the actual result of a test doesn't match the 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.

Question 10[3 marks]
This algorithm crashes if the user enters 0 as the number of people, because it can't divide by 0. Refine it so it asks again until a number above 0 is entered.
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

Question 11[2 marks]
State which type of testing is being used in each case.
  1. A programmer tests the login procedure as soon as they finish writing it.
  2. 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.

Question 12[4 marks]
A program should accept a test mark from 0 to 50. Complete the test plan by giving the type of test data and the expected result for each test.
Test dataType of test dataExpected 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.

Question 13[4 marks]
This code should output Pass for a score of 40 or more. It has one syntax error and one logic error. Identify each error and say how to fix it.
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.

Question 14[2 marks]
Explain why testing a program with only normal data is not enough.
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.