You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson covers the selection and use of test data as required by OCR J277 Section 2.4. To test a program effectively, you need to choose appropriate test data that covers all possible scenarios. OCR requires you to understand three types of test data: normal, boundary, and erroneous/invalid.
Using the right test data is critical because:
OCR Exam Tip: Test data questions are extremely common on Paper 2 and are typically worth 3–6 marks. You must know the three types of test data and be able to select appropriate examples for any given scenario.
Normal data (also called valid data or typical data) is data that the program should be able to handle — data that falls well within the acceptable range and is in the correct format.
Normal data tests that the program works correctly under typical conditions.
Example: For a program that accepts exam marks from 0 to 100:
Boundary data tests the values at the edges of the acceptable range — the minimum and maximum values that should be accepted, and values just outside the range that should be rejected.
Boundary testing is crucial because many bugs occur at the boundaries of ranges (off-by-one errors).
Example: For marks from 0 to 100:
| Value | Type | Expected Result |
|---|---|---|
| -1 | Just below lower boundary | Rejected |
| 0 | Lower boundary (valid) | Accepted |
| 1 | Just above lower boundary | Accepted |
| 99 | Just below upper boundary | Accepted |
| 100 | Upper boundary (valid) | Accepted |
| 101 | Just above upper boundary | Rejected |
OCR Exam Tip: When asked for boundary test data, always give values ON the boundary AND values just outside the boundary. For a range of 0–100, give: -1 (rejected), 0 (accepted), 100 (accepted), 101 (rejected). This tests that the boundaries are implemented correctly.
Erroneous data (also called invalid data) is data that should be rejected by the program. It is data that is the wrong type, format, or is otherwise unacceptable.
Erroneous data tests that the program's validation works correctly and handles bad input without crashing.
Example: For a program that accepts exam marks (integer, 0–100):
| Test Data | Type | Expected Outcome | Purpose |
|---|---|---|---|
| 50 | Normal | Accepted | Typical valid input |
| 75 | Normal | Accepted | Another typical value |
| 0 | Boundary | Accepted | Lower boundary |
| 100 | Boundary | Accepted | Upper boundary |
| -1 | Boundary | Rejected | Just below lower boundary |
| 101 | Boundary | Rejected | Just above upper boundary |
| "abc" | Erroneous | Rejected — error message | Wrong data type |
| "" | Erroneous | Rejected — error message | Empty input |
| 3.14 | Erroneous | Rejected — error message | Real number, not integer |
flowchart TD
TD[Test data] --> N[Normal / Valid / Typical]
TD --> B[Boundary / Extreme]
TD --> E[Erroneous / Invalid]
N --> N1["Inside range, correct type<br/>e.g. 50, 75"]
B --> B1["On the limit — accepted<br/>e.g. 0, 100"]
B --> B2["Just outside the limit — rejected<br/>e.g. -1, 101"]
E --> E1["Wrong type<br/>e.g. ’abc’, 3.14"]
E --> E2["Empty / missing<br/>e.g. ’’"]
E --> E3["Far out of range<br/>e.g. -500"]
A password must be between 8 and 20 characters and must contain at least one digit.
| Test Data | Type | Expected Outcome | Reason |
|---|---|---|---|
| "Secure99" | Normal | Accepted | 8 chars, contains digit |
| "MyP4ssword123" | Normal | Accepted | 13 chars, contains digits |
| "Pass1234" | Boundary | Accepted | Exactly 8 characters (lower boundary) |
| "AbCdEfGh1234567890iJ" | Boundary | Accepted | Exactly 20 characters (upper boundary) |
| "Short1" | Boundary | Rejected | 6 characters — too short |
| "ThisPasswordIsTooLong1" | Boundary | Rejected | 22 characters — too long |
| "NoDigits" | Erroneous | Rejected | No digit present |
| "" | Erroneous | Rejected | Empty input |
| "1234567" | Boundary | Rejected | 7 characters — just below minimum |
A test plan combines all test data types into a structured table:
Scenario: A program asks the user for their age (integer, 0–150) and displays a message.
| Test # | Input | Data Type | Expected Output | Actual Output | Pass? |
|---|---|---|---|---|---|
| 1 | 25 | Normal | "You are 25 years old" | ||
| 2 | 75 | Normal | "You are 75 years old" | ||
| 3 | 0 | Boundary | "You are 0 years old" | ||
| 4 | 150 | Boundary | "You are 150 years old" | ||
| 5 | -1 | Boundary | "Invalid age" | ||
| 6 | 151 | Boundary | "Invalid age" | ||
| 7 | "abc" | Erroneous | "Please enter a number" | ||
| 8 | "" | Erroneous | "Age cannot be empty" | ||
| 9 | 3.5 | Erroneous | "Please enter a whole number" |
OCR Pseudocode — validated input with all checks:
do
ageInput = input("Enter your age (0-150): ")
valid = true
if ageInput == "" then
print("Error: age cannot be empty")
valid = false
elseif NOT ageInput.isNumeric() then
print("Error: please enter a whole number")
valid = false
elseif int(ageInput) < 0 OR int(ageInput) > 150 then
print("Error: age must be between 0 and 150")
valid = false
endif
until valid == true
age = int(ageInput)
print("You are " + str(age) + " years old")
Python:
while True:
age_input = input("Enter your age (0-150): ")
if age_input == "":
print("Error: age cannot be empty")
elif not age_input.isdigit():
print("Error: please enter a whole number")
elif int(age_input) < 0 or int(age_input) > 150:
print("Error: age must be between 0 and 150")
else:
break
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.