← QCE Digital Solutions Unit 4

Testing a prototype for reliability

Checking a prototype keeps working when the data source is offline, missing, empty, slow or sends malformed data, and gives consistent results on repeated runs.

Understanding Testing a prototype for reliability in QCE Digital Solutions Unit 4

What it does: Running the prototype with the file removed raises FileNotFoundError, so catching it shows the prototype handles a missing source. A timeout makes the request give up after 5 seconds, so a slow or unavailable source cannot freeze the prototype. Consistent results on repeated runs with the same input is a key sign of reliability. Empty data can cause errors like IndexError or KeyError. Reliability testing checks that the prototype handles it gracefully. Reliability is about how the prototype behaves when things go wrong, not just when everything works. A reliability test with no internet triggers ConnectionError, and this except block lets the prototype keep working.

Common mistakes: There is no timeout, so a slow or unresponsive source can make the prototype hang forever. A reliability test needs a limit, so it should be r = get(url, timeout=5). Opening in 'w' mode creates an empty file instead of raising FileNotFoundError, so the missing-file test never runs. It should be open('data.csv') in read mode.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 334–401) and word search (Modules 127–401).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which test checks reliability of an API prototype?
Check the button colours match the style guideTurn off the internet and run it to see if it shows a friendly error message
Matches
data = json.loads(text) print(data["name"])
↓
No try/except around json.loads, so malformed JSON or a missing key crashes the prototype. A reliability test with broken data would fail.
Applying
Meanings
Term
reliability testing
Meaning
Checking a prototype keeps working when the data source is offline, missing, empty, slow or sends malformed data, and gives consistent results on repeated runs.
Practice
import json
Testing
Gaps
except requests.:
Check Answer
Spots
1from requests import get
2r = get(url)

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Wolverine' badge — Fearless Coder, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which test checks reliability of an API prototype?
A. Turn off the internet and run it to see if it shows a friendly error message ✓
B. Check the button colours match the style guide
Reliability testing checks the prototype still works when the source is unavailable, such as when there is no connection.
2. A prototype reads data from scores.csv. Which reliability test is most useful?
A. Rename or delete scores.csv and run it to check it handles the missing file ✓
B. Only run it when scores.csv is present and correct
A missing file is a common failure. A reliable prototype catches it (for example with try/except FileNotFoundError) instead of crashing.
3. Which input is a good malformed JSON test?
A. {"name": "Ava", "age": 17}
B. {"name": "Ava", "age": 17 ✓
The first string is missing its closing brace, so json.loads() raises an error. A reliable prototype should handle that without crashing.
4. Which XML snippet is malformed and should be used to test reliability?
A. <student><name>Ava</name></student>
B. <student><name>Ava</student> ✓
The <name> tag is never closed, so ElementTree raises a ParseError. Reliability testing checks that the prototype handles this.
5. Which result shows a prototype is reliable when run repeatedly?
A. Running it 10 times with the same input gives the same output each time ✓
B. Running it 10 times gives a different output each time with the same input
Consistent results on repeated runs with the same input is a key sign of reliability.

Match the Pairs

except requests.exceptions.ConnectionError: → Handles the no connection case so the prototype shows a message instead of crashing when the API is offline
except json.JSONDecodeError: → Catches malformed JSON so the prototype copes when the source sends broken data
Reliability test for a missing file: the prototype must not crash when the data file does not exist → except FileNotFoundError:
Reliability test for slow sources: the prototype stops waiting after a set time instead of freezing → requests.get(url, timeout=5)
data = json.loads(text) print(data["name"]) → No try/except around json.loads, so malformed JSON or a missing key crashes the prototype. A reliability test with broken data would fail.
Test run 1 only: works, so the prototype is reliable → Reliability needs repeated runs and awkward conditions such as offline, empty or malformed data. One successful run does not prove consistent results.

Key Term

reliability testing
Checking a prototype keeps working when the data source is offline, missing, empty, slow or sends malformed data, and gives consistent results on repeated runs.

Fill in the Blanks

1. try: r = requests.get(url, timeout=5) except requests.ConnectionError:
Hint: Type the exception name raised when the device has no network connection.
2. try: f = open('data.csv') except FileNotFoundError:
Hint: Type the built-in exception raised when the file does not exist.
3. try: data = json.loads(text) except json.JSONDecodeError:
Hint: Type the json exception raised when the text is malformed and cannot be parsed.
4. if len(rows) == 0: print("No data returned")
Hint: Type the built-in function that counts the items in a list, to detect an empty result.
5. for run in range(3): print(get_total())
Hint: Type the built-in function that produces a sequence of numbers, so the same call is repeated three times to check results stay consistent.

Spot the Error

Question 1
A from requests import get
B r = get(url)
C print(r.status_code)
Line B — There is no timeout, so a slow or unresponsive source can make the prototype hang forever. A reliability test needs a limit, so it should be r = get(url, timeout=5).
Question 2
A try:
B f = open('data.csv', 'w')
C text = f.read()
D except FileNotFoundError:
E print('File missing')
Line B — Opening in 'w' mode creates an empty file instead of raising FileNotFoundError, so the missing-file test never runs. It should be open('data.csv') in read mode.
Question 3
A import json
B bad = '{"id": 1,'
C try:
D data = json.load(bad)
E except json.JSONDecodeError:
F data = {}
Line D — json.load reads from a file object, not a string, so it raises an error that the except clause does not catch. Use json.loads(bad) to parse a JSON string.
Question 4
A def average(m):
B if len(m) == 0:
C pass
D return sum(m) / len(m)
Line C — Using pass means an empty list falls through to the division and causes ZeroDivisionError. The empty-data case should return 0 (or another safe value).
Question 5
A def total(p):
B return sum(p)
C first = total([4, 6, 10])
D second = total([4, 6, 11])
E assert first == second
Line D — A repeat-run test must use the same input both times. Different input makes the comparison meaningless. It should be total([4, 6, 10]).

Student with a class code? Join your class →