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

Free lesson

ESP tasks 2, 4a: Test your work and keep proof

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

45 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

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.

Match the value to its test type

Have a go

Loading…

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

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

Note

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

Warning

Many people fill in the expected result after the test. Then they copy what happened, every test passes, and the plan shows nothing. Write what should happen first, from what the brief asks.

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.

Make a free account to save your work and track your progress.

Check: test plans and test data

Have a go

Check: test plans and test data

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

Stage 4a: write the hour check

This is stage 4a of the Hillside practice project. Write valid_hour. It takes what a person typed and gives back the hour as an integer if it is a whole number from 9 to 20. For anything else it gives back None. Think about empty text, words, decimals (like 10.5), numbers below zero and spaces. Press Run Tests to check your work.

Code: python
def valid_hour(text):
    # text is what a person typed, such as "10" or " 9 ".
    # Give back the hour as an integer if it is a whole number from 9 to 20.
    # Spaces at the start or end are fine.
    # Give back None for anything else: empty text, words, decimals, 8, 21.
    return None

Make a free account to save your work, or press Start lab to work through the whole lesson.

A screenshot for each test is proof

A test with no proof is only words. Keep evidence.

Take a screenshot of each result. Name the file with the test number: test-05-hour-21.png. Put the date and time in your log.

If a test fails, keep the screenshot of the failure too. Then show the fix and the second run.

Good and weak evidence

WeakGood
"I tested it and it worked"A table with the data, the expected result, the actual result and a screenshot
One screenshot of one passA screenshot for each test number, including failures
No dateDate and time in the log
Fixed code with no noteThe failing run, the change and the passing run

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

Stage 4a: your test plan

Write a test plan for your book function from the last lesson. Use a table with the columns: No., Purpose, Data, Type, Expected, Actual, Action. Write at least ten tests. Include valid, valid extreme, invalid, invalid extreme and erroneous data. Write the Purpose and Expected first. Then run each test and fill in Actual. Add a screenshot or a copy of the output for at least three of them. If a test fails, write what you changed in the Action column and run it again.

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

Final check

6 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

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.