Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

Test your work and keep proof

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

45 minutes

It works, for you

Your booking code works. You typed 10 and it booked the hour.

Now a tester types "abc". Then 9. Then 21. Then nothing at all. Your code stops with an error.

You are the person who knows the code, so you try the easy things. A good tester tries the things that break it.

Key words

WordWhat it meansExample
Test planA table of tests written before you run them.hour 21: expect refused
Test dataThe values you use in a test.10, 21, "abc"
Valid dataA value the program should accept.14
Invalid dataThe right kind of value, but not allowed. The program should refuse it.5
Extreme dataA value at the very edge of the allowed range: the first or the last one.9 and 20 are valid. 8 and 21 are invalid.
Erroneous dataThe wrong kind of value. The program should refuse it.the word "abc" for an hour
Expected resultWhat should happen, written before the test.Refused
Actual resultWhat really happened.Booked
EvidenceProof that you ran the test and what happened.a screenshot

The cells students fill in are left blank in this preview.

A test plan for the hour check

No.PurposeDataTypeExpectedActualAction
1Accept a sensible hour14ValidBooked
2Accept the first hour9Valid extremeBooked
3Accept the last hour20Valid extremeBooked
4Refuse just too early8Invalid extremeRefusedBooked (wrong)Change the check to start at 9, then run again
5Refuse just too late21Invalid extremeRefused
6Refuse a very wrong hour5InvalidRefused
7Refuse wordsabcErroneousRefused
8Refuse nothing typed(empty)ErroneousRefused

The cells students fill in are left blank in this preview.

Where the full table is needed

data-callouts.note.label

Task 2 asks for tests with proof: the purpose, the data, what you expect, what happened, and what you do next. Task 4a says a formal test document is not needed there. You must still test, so your product works. Practise the full table here.

Write the expected result first

data-callouts.warning.label

Write what should happen before you run the test. If you write it after, you may write what happened instead. Then every test passes, and the plan shows nothing.

Try it: a test is a small program

Code: python
def valid_hour(text):
    if text.isdigit():
        hour = int(text)
        if hour >= 9 and hour <= 20:
            return hour
    return None


def check(number, data, expected):
    actual = valid_hour(data)
    result = "FAIL"
    if actual == expected:
        result = "PASS"
    print(number, data, "expected", expected, "got", actual, result)


check(1, "14", 14)
check(2, "9", 9)
check(3, "21", None)
check(4, "abc", None)

# isdigit() checks the text is only digits.
# >= means "is more than or equal to". <= means "is less than or equal to".
# Add a test for "8". Run it.

Quick check: test plans

Have a go

Quick check: test plans

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

The lesson goes on

5 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.