AQA GCSE Computer Science (8525), section 3.2.11 (Robust and secure programming)
Why test?
Testing means running a program or algorithm with chosen data to see if it works correctly and to find errors. Testing finds faults, but cannot prove there are none.
Test data
Test data is the data used in testing. There are three types.
| Type | Meaning | Example (a mark from 1 to 10) |
|---|---|---|
| Normal (typical) | data the program should accept | 5 |
| Boundary (extreme) | data at the edge of what is allowed, and just outside it | 0, 1, 10, 11 |
| Erroneous | data that is wrong and should be rejected | "abc", -4, 99 |
For the range 1 to 10, the boundary data is 0, 1, 10 and 11: either side of each boundary. Values 1 and 10 are accepted; 0 and 11 are rejected.
A test plan
Choose the data before running the program, and write down what you expect.
| Test | Data | Type | Expected result |
|---|---|---|---|
| 1 | 5 | normal | accepted |
| 2 | 1 | boundary | accepted |
| 3 | 10 | boundary | accepted |
| 4 | 0 | boundary | rejected |
| 5 | 11 | boundary | rejected |
| 6 | "abc" | erroneous | rejected |
def valid(value):
return isinstance(value, int) and 1 <= value <= 10
for data in [5, 1, 10, 0, 11, "abc"]:
print(data, valid(data))
# 5 True, 1 True, 10 True, 0 False, 11 False, abc False
Selecting and justifying data
When asked to justify a choice, say what the data tests. For example: "10 is used because it is the largest valid value, so it tests whether the upper boundary is handled correctly."
Refining
After testing, fix any errors and test again, to make sure the fix works and has not caused new problems.
Common mistake: listing only the valid boundary values. Boundary data includes values just outside the range (0 and 11), which should be rejected. Also, erroneous data is the wrong type or clearly nonsense, not just a boundary value.
Exam tip: for a range question, give both ends of the range and the values just outside. State the type of each test and the expected result.
Check yourself
What are the three types of test data?
Normal (typical), boundary (extreme) and erroneous.
Give the boundary test data for a valid range of 1 to 100.
0, 1, 100 and 101.
Give an example of erroneous data for an age field.
Text such as "hello", or a negative number.