Testing a prototype for reliability

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Testing a prototype for reliability

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

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
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
3. Which input is a good malformed JSON test?
A {"name": "Ava", "age": 17}
B {"name": "Ava", "age": 17
4. Which XML snippet is malformed and should be used to test reliability?
A <student><name>Ava</name></student>
B <student><name>Ava</student>
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

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

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

Definitions

reliability testing

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
try: r = requests.get(url, timeout=5) except requests._______________:
2.
try: f = open('data.csv') except _________________:
3.
try: data = json.loads(text) except json._______________:
4.
if ___(rows) == 0: print("No data returned")
5.
for run in _____(3): print(get_total())

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A from requests import get
B r = get(url)
C print(r.status_code)
Question 2
A try:
B f = open('data.csv', 'w')
C text = f.read()
D except FileNotFoundError:
E print('File missing')
Question 3
A import json
B bad = '{"id": 1,'
C try:
D data = json.load(bad)
E except json.JSONDecodeError:
F data = {}
Question 4
A def average(m):
B if len(m) == 0:
C pass
D return sum(m) / len(m)
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

Answer Key

Testing a prototype for reliability
Section A: Quick Questions
Q1
A — Turn off the internet and run it to see if it shows a friendly error message
Q2
A — Rename or delete scores.csv and run it to check it handles the missing file
Q3
B — {"name": "Ava", "age": 17
Q4
B — <student><name>Ava</student>
Q5
A — Running it 10 times with the same input gives the same output each time
Section B: Match the Pairs
Q1
except requests.exceptions.ConnectionError: → Handles the no connection case so the prototype shows a message instead of crashing when the API is offline
Q2
except json.JSONDecodeError: → Catches malformed JSON so the prototype copes when the source sends broken data
Q3
Reliability test for a missing file: the prototype must not crash when the data file does not exist → except FileNotFoundError:
Q4
Reliability test for slow sources: the prototype stops waiting after a set time instead of freezing → requests.get(url, timeout=5)
Q5
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.
Q6
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.
Section C: Definitions
Q1
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.
Section D: Fill in the Blanks
Q1
try: r = requests.get(url, timeout=5) except requests.ConnectionError:
Q2
try: f = open('data.csv') except FileNotFoundError:
Q3
try: data = json.loads(text) except json.JSONDecodeError:
Q4
if len(rows) == 0: print("No data returned")
Q5
for run in range(3): print(get_total())
Section E: Spot the Error
Q1
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).
Q2
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.
Q3
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.
Q4
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).
Q5
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]).