Fix one bug, break another
You fix a bug in the cancel code. The cancel tests pass. You are happy.
Then somebody joins the waiting list and everything stops. Your fix changed something another part needed.
Good testing finds this early. There is more than one kind of test, and each finds a different kind of fault.
Key words
| Word | What it means | Example |
|---|---|---|
| Module testing | Testing one part of the program on its own. | test next_in_line alone |
| Integration testing | Testing that parts work together as one system. | cancel, then promote |
| Automated testing | Tests that a program runs for you. | the Run Tests button |
| User testing | Watching real people use the solution. | a desk worker tries it |
| Regression testing | Running old tests again after a change, to check nothing broke. | run all tests after a fix |
| Function | A named piece of code that does one job. | cancel() |
| Promote | Move a person from the waiting list into a booking. | Aisha is promoted when Sam cancels |
| Bug report | A clear note about a fault: what, where, how to see it. | Promote leaves a name in the list |
| Change log | A list of what changed, when and why. | v3: fixed promote |
| Test data | The values you type in to test. | hour 12, hour 21 |
The cells students fill in are left blank in this preview.
Match the test to what it finds
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Four kinds of test on the waiting list
| Kind | Hillside example | Who or what runs it |
|---|---|---|
| Module | next_in_line gives the first name for a slot | The developer |
| Integration | A cancel gives the court to the first person waiting | The developer |
| Automated | All the tests run when you press one button | A program |
| User | A desk worker tries to join Sam to the list | A real person |
The cells students fill in are left blank in this preview.
Try it: a tiny automated test
def next_in_line(waiting, court, hour):
for one in waiting:
if one["court"] == court and one["hour"] == hour:
return one["member"]
return None
def test_first_name():
waiting = [{"member": "Sam", "court": 1, "hour": 10}]
assert next_in_line(waiting, 1, 10) == "Sam"
def test_nobody():
assert next_in_line([], 1, 10) is None
for test in (test_first_name, test_nobody):
test()
print(test.__name__, "passed")
Make a free account to save your work and track your progress.
Check: which kind of test?
Have a go
Check: which kind of test?
5 questionsFive kinds of test data
| Kind | Hillside example (hours 9 to 20 are open) | Expected |
|---|---|---|
| Valid | Hour 12 | Booked |
| Valid extreme (the edge that still works) | Hours 9 and 20 | Booked |
| Invalid | Hour 30 | Refused |
| Invalid extreme (just past the edge) | Hours 8 and 21 | Refused |
| Erroneous (the wrong kind of data) | The word "ten" | Refused with a clear message |
The cells students fill in are left blank in this preview.
Try it: run the five kinds of data
def book(bookings, member, court, hour):
if hour < 9 or hour > 20 or court not in (1, 2):
return False
bookings.append({"member": member, "court": court, "hour": hour})
return True
tests = [("normal", 12), ("lowest valid", 9), ("highest valid", 20),
("too low", 8), ("too high", 21), ("wrong type", "ten")]
for test in tests:
kind = test[0]
hour = test[1]
try:
print(kind, hour, "->", book([], "Sam", 1, hour))
except TypeError:
print(kind, hour, "-> CRASH: text cannot be compared with a number")
# The last test finds a fault. How would you fix it?
Make a free account to save your work and track your progress.
Task 2 practice: fix the join
Task 2 practice. The parts of the waiting list each pass their own tests. But cancel_and_promote, which joins them, has two faults. Run the tests, read the messages and find both. Fix the function. Then run all tests again. Press Run Tests to check your work.
def is_free(bookings, court, hour):
for one in bookings:
if one["court"] == court and one["hour"] == hour:
return False
return True
def book(bookings, member, court, hour):
if hour < 9 or hour > 20 or court not in (1, 2):
return False
if not is_free(bookings, court, hour):
return False
bookings.append({"member": member, "court": court, "hour": hour})
return True
def cancel(bookings, member, court, hour):
for one in bookings:
if one["member"] == member and one["court"] == court and one["hour"] == hour:
bookings.remove(one)
return True
return False
def next_in_line(waiting, court, hour):
for one in waiting:
if one["court"] == court and one["hour"] == hour:
return one["member"]
return None
def leave_waiting_list(waiting, member, court, hour):
for one in waiting:
if one["member"] == member and one["court"] == court and one["hour"] == hour:
waiting.remove(one)
return True
return False
def cancel_and_promote(bookings, waiting, member, court, hour):
# Cancel the member's booking. If somebody is waiting for that court and hour,
# give the court to the first person and take them off the waiting list.
# Give back the name of the person who got the court, or None.
# The parts above each pass their own tests. The problem is where they join.
cancel(bookings, member, court, hour)
promoted = next_in_line(waiting, court, hour)
if promoted is not None:
book(bookings, promoted, court, hour)
return promoted
Make a free account to save your work, or press Start lab to work through the whole lesson.
A bug report lets anybody see the fault
With a good bug report, anybody can make the fault happen again. It says what you did, what you expected and what happened.
It also says how serious it is. Keep it short. Do not just write "it is broken".
A bug report, and a change log line
| Field | Example |
|---|---|
| Title | Promoted member stays on the waiting list |
| Steps | Sam cancels court 1 at 10. Aisha is first in the line. |
| Expected | Aisha gets the court and leaves the list |
| Actual | Aisha gets the court but is still on the list |
| Severity (how serious it is) | High: the same person can be promoted again |
| Cause | Application error: the code did not remove the name |
| Change log | v4: cancel_and_promote now removes the promoted member from the list |
| Told | Who was told the fix is ready, and on which day: the desk manager |
| Lesson learned | Test the join between two parts, not only each part |
The cells students fill in are left blank in this preview.
After a fix: run everything
Important
Run the test that failed. Then run every other test too. This is regression testing. Write the result in your change log. A fix is not finished until the old tests still pass.
Task 2 practice: report and log
Write a bug report for each of the two faults you fixed. Use the fields Title, Steps, Expected, Actual, Severity and Cause. Then write a change log with two lines, one for each fix, each with a version number. Last, write two sentences about the regression check you ran after the fixes.
A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.
Make a free account to save your work, or press Start lab to work through the whole lesson.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Final check
Have a go