Testing

GCSE Computer Science (OCR) · OCR J277 · 2.3.2 · Algorithms and programming (Paper 2) › Producing robust programs

66 exam-style questions plus unlimited generated ones on this topic, at up to four difficulty levels, with full mark schemes. Notes and past-paper booklets are open to everyone. Practice needs a free account.

Or take a quick quiz: 10 questions on this subtopic in GCSE Computer Science (OCR), marked as you tap.

Revision notes

Testing checks that a program works and meets its requirements. You need to know why we test, the difference between iterative and final (terminal) testing, how to identify syntax and logic errors, and how to choose normal, boundary, invalid and erroneous test data. Expect test-plan tables and questions that use test results to find an error.

Key facts

  • Purpose: find and fix errors; check the program meets the requirements
  • Iterative testing: test each part during development, fix, test again
  • Final (terminal) testing: test the whole program at the end
  • Syntax error: breaks the language's grammar rules, so the code cannot be translated or run
  • Logic error: the program runs but gives unexpected output
  • Normal: sensible, valid data (accepted)
  • Boundary: at the edge of the valid range (accepted)
  • Invalid: correct data type but outside the range (rejected)
  • Erroneous: wrong data type (rejected)
  • Test plan: test data, type of test, expected result (then actual result)

Notes

Why and when to test

diagram
  • The purpose of testing is to find errors so they can be fixed, and to check the program meets its requirements and copes with unexpected input without crashing.
  • Iterative testing: each part (module) is tested while it is being developed. Errors are fixed and the part is tested again, over and over.
  • Final (terminal) testing: the whole program is tested at the end of development, to check every part works together and all the requirements are met.
  • Iterative testing (during development)Final testing(at the end)Write orchange codeTest themoduleerrors found: fix, then test againTest thewhole programall partsdone
    Iterative testing happens over and over during development; final testing happens once at the end
  • Syntax errors break the grammatical rules of the programming language, so the program cannot be translated or run; the translator reports them. Logic errors let the program run but give the wrong result; they are found by testing.

Types of test data (rule: a whole number from 1 to 100)

diagram
  • Normal: sensible data that should be accepted, such as 50.
  • Boundary: data at the very edge of the valid range, such as 1 and 100, which should be accepted. Values just outside, such as 0 and 101, are also worth testing: they should be rejected.
  • Invalid: data of the correct data type that is outside the allowed range, such as 150, which should be rejected.
  • Erroneous: data of the wrong data type, such as "ten" or 7.5, which should be rejected.
  • 0rejectjust outside1acceptboundary50acceptnormal100acceptboundary101rejectjust outside150rejectinvaliderroneous (wrong data type): "ten", 7.5reject
    Test data for the rule 'a whole number from 1 to 100' (not to scale)
  • Boundary tests matter because a small slip, such as < instead of <=, only shows up at the limit.

Test plans and refining

  • A test plan lists each test: what is being tested, the test data, the type of test and the expected result. When the test is run, the actual result is recorded.
  • If the actual result is different from the expected result, there is an error to find and fix.
  • Refining an algorithm means correcting or improving it after testing, then testing it again.

How to answer each type of question

Complete a test plan

3 to 5 marksGrade 5
  1. Read the rule: which values should be accepted?
  2. Pick data for each type asked: normal, boundary, invalid, erroneous.
  3. Give the expected result for each: accepted, or rejected with an error message.
  4. Every test needs both the data and the correct expected result.

Example. A program accepts a number of tickets from 1 to 8. Complete a test plan with one test of each type: normal, boundary, invalid and erroneous. Give the test data and the expected result for each. [4]

Show the model answerHide the model answer
Type of testTest dataExpected result
Normal4Accepted (1)
Boundary8 (or 1)Accepted (1)
Invalid9 (or 0)Rejected, error message shown (1)
Erroneous"two"Rejected, error message shown (1)

Describe iterative and final testing

2 to 4 marksGrade 5
  1. Iterative: during development, each part tested and retested as it is written.
  2. Final: at the end, the whole program tested against the requirements.
  3. If asked 'why both', say parts that work alone may not work together.

Example. Describe the difference between iterative testing and final testing. [2]

Show the model answerHide the model answer
Iterative testing is carried out during development: each part of the program is tested as it is written, and fixed and retested (1). Final testing is carried out on the whole program at the end of development, to check it meets all the requirements (1).

Use test results to find an error

3 to 4 marksGrade 7
  1. Compare each expected result with the actual result.
  2. The test where they differ shows the error.
  3. Look at the line that makes that decision and rewrite it correctly.

Example. A pass needs a mark of 40 or more.

01 mark = int(input("Enter mark"))
02 if mark > 40 then
03    print("Pass")
04 else
05    print("Fail")
06 endif
Tests: 55 outputs Pass; 40 outputs Fail; 12 outputs Fail.
Identify the test that shows an error, state the type of error and write the corrected line. [3]

Show the model answerHide the model answer
The test with 40 (boundary data): it should output Pass but outputs Fail (1). It is a logic error (1). Line 02 should be if mark >= 40 then (1).

Don’t lose marks

  • Mixing up invalid (right type, out of range) and erroneous (wrong type).
  • Giving test data without an expected result, or with only 'works'.
  • Choosing boundary data that is not actually on the limit, such as 2 for a range starting at 1.
  • Saying testing proves a program has no errors: it can only show the errors it finds.
  • Describing final testing as 'testing the last part of the code'.

More tips

Memory tricks

  • Rule 1 to 100 test set: 50 (normal), 1 and 100 (boundary), 150 (invalid), "ten" (erroneous).
  • Invalid = right type, wrong range. Erroneous = wrong type altogether.
  • Iterative = as you go; final = at the end.

Exam technique

  • Write expected results as 'accepted' or 'rejected (error message shown)', not 'correct'.
  • Use the exact limits from the question for boundary data.
  • When finding an error from test results, quote the test data and both the expected and the actual result.

What each grade needs

What you need to be able to do, from the first marks up to the top grade.

  1. Grade 3
    State the purpose of testingTo find and fix errors, and check the program meets its requirements.
  2. Grade 4
    Give examples of each type of test dataNormal, boundary, invalid and erroneous data for a given rule.
  3. Grade 5
    Complete a test plan with expected resultsGive test data, its type and whether it should be accepted or rejected.
  4. Grade 5
    Compare iterative and final testingIterative happens during development; final testing is of the whole program at the end.
  5. Grade 6
    Explain why boundary data is testedErrors often happen at the limits, for example < used instead of <=.
  6. Grade 7
    Use test results to find and fix errorsCompare expected and actual results to locate a logic error and correct the line.

Quick recall

Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.

Name the type of error that is caused when a programmer breaks the rules of the programming language.
Syntax error
A programmer types pritn("Hello") instead of print("Hello").
Syntax error
Data that is typical and should be accepted by the program is called ______ data.
normal
A programmer writes a test plan. State two things that a test plan records for each test.
Any two of: purpose, test data, expected outcome, actual outcome.
Give one example of normal data and one example of erroneous data for this program.
Normal: 7. Erroneous: “June”.
State what is meant by the expected outcome of a test.
The result the program should give for that test data if it is working correctly.

Sample questions

Written for this site in the style of OCR exam questions. They are not taken from real past papers.

Question 1Easy3 marks
(a) Give two reasons why programs are tested.
[2]
(b) State what is meant by final (terminal) testing.
[1]
Show the answer and mark scheme
(a)
  • to find errors / bugs (so they can be fixed)
  • to check that the program meets the requirements / does what it should
  • to check that the program handles invalid / unexpected data without crashing
  • to make sure the program is reliable before it is released
(b)
  • testing the whole program once it is complete / at the end of development (to check that it meets the requirements)
Question 2Medium6 marks
(a) Describe what is meant by iterative testing.
[2]
(b) Explain one advantage of iterative testing.
[2]
(c) Explain why final testing is still needed when iterative testing has been carried out.
[2]
Show the answer and mark scheme
(a)
  • testing each part / module of the program while it is being developed
  • errors are fixed and the code is tested again, repeatedly
(b)
  • errors are found early / in small sections of code
  • so they are easier to locate and fix (and cost less to fix than at the end)
(c)
  • modules that work on their own may not work correctly together
  • the whole program must be checked against the requirements before it is released
Question 3Hard6 marks
A password must be from 8 to 16 characters long and must contain at least one digit.
(a) Design a test plan with five tests for this rule. For each test give the test data, the type of test and the expected result.
[5]
(b) Explain why passwords of exactly 7 and exactly 17 characters should also be tested.
[1]
Show the answer and mark scheme
(a)
  • normal: e.g. river2024 (9 characters with a digit), accepted
  • boundary: exactly 8 characters with a digit, accepted
  • boundary: exactly 16 characters with a digit, accepted
  • invalid: 7 (or 17) characters with a digit, rejected
  • invalid: correct length but no digit, rejected
  • invalid (or erroneous): a blank / empty password, rejected
(b)
  • they are just outside the boundaries, so they check that the limits are in exactly the right place (they must be rejected)

More in Producing robust programs

Stuck? Get 1-to-1 help.

Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.