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

Free lesson

2.12 (3 of 3): Test data and test plans

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.

50 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

Testing a lift

A lift (an elevator in a building) has a sign: maximum 8 people. How would you test it?

Try 3 people. Try exactly 8. Try 9. Try 0. What about a chair, or a dog? Each of these is a different kind of data for a test. The values you use to test are called test data (the data you test with). Good testers choose it carefully.

Key words

WordWhat it meansExample
Test dataThe values you give to a program to test it.
Valid dataData the program should accept: the right kind and inside the limits.55 for a mark of 0 to 100
Invalid dataThe right kind of data, but outside the limits. The program should reject it.150
Boundary dataValues on the edges of the limits, and the first values just outside them.0, 100, -1, 101
Erroneous dataThe wrong kind of data. The program should reject it."abc"
Test planA table that lists each test, its data and its expected result.
Expected resultWhat should happen, decided before the test.
Actual resultWhat really happened when you ran the test.

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

Four kinds of test data

KindExample for a mark from 0 to 100Expected result
Valid55Accepted
Invalid150Rejected: it is outside the limits
Boundary0, 100, and the values just outside: -1 and 101Accepted on the edge. Rejected just outside
Erroneous"abc" or nothing at allRejected: it is not a whole number

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

Which kind of data is it?

Have a go

Loading…

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

Why edges matter

Many bugs are at the edges of the limits. A programmer writes age > 13 when they should write age >= 13. Test data of 5 or 15 never finds it. Only 13 does. (With age > 13, the value 13 is wrongly rejected.)

So always test the lowest and highest valid values, and the first value outside each one.

Try it: run the test data

Code: python
def mark_ok(text):
    return text.isdigit() and int(text) >= 0 and int(text) < 100

for data in ["55", "0", "100", "101", "abc"]:
    print(data, mark_ok(data))

# One answer is wrong. Which data found the bug? What is the bug?

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

A test plan comes before testing

A test plan is written before the testing starts. It says what you will test, why, with what data, and what should happen.

You fill in the last column during the test. If the actual result is not the expected result, the test fails and you have found a bug.

A test plan for a mark

TestPurposeTest dataExpected resultActual result
1Valid data in the middle is accepted55AcceptedFill in when you run it
2The lowest valid mark is accepted0AcceptedFill in when you run it
3The highest valid mark is accepted100AcceptedFill in when you run it
4A mark just above the top is rejected101RejectedFill in when you run it
5A mark just below the bottom is rejected-1RejectedFill in when you run it
6Text instead of a number is rejectedabcRejectedFill in when you run it

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

Quick check: the plan

Have a go

Quick check: the plan

4 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

Try it: record the actual results

Code: python
def mark_ok(text):
    return text.isdigit() and int(text) >= 0 and int(text) <= 100

data = ["55", "0", "100", "101", "-1", "abc"]
expected = ["Accepted", "Accepted", "Accepted", "Rejected", "Rejected", "Rejected"]

for i in range(len(data)):
    if mark_ok(data[i]):
        actual = "Accepted"
    else:
        actual = "Rejected"
    if actual == expected[i]:
        print(data[i], "PASS")
    else:
        print(data[i], "FAIL")

# Change <= 100 to < 100. Which test fails?

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

Extra: Try it: a test that crashes

Code: python
def mark_ok(text):
    return int(text) >= 0 and int(text) <= 100

data = ["55", "101", "abc"]
expected = ["Accepted", "Rejected", "Rejected"]

for i in range(len(data)):
    try:
        if mark_ok(data[i]):
            actual = "Accepted"
        else:
            actual = "Rejected"
    except ValueError:
        actual = "Crashed"
    if actual == expected[i]:
        print(data[i], actual, "PASS")
    else:
        print(data[i], actual, "FAIL")

# This mark_ok has no isdigit() check, so "abc" crashes it.
# A crash is always a FAIL. Write Crashed in the actual result column.

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

Your turn: build a test plan

Build the parts of a test plan for a field that takes a whole number from low to high, typed as text.

  1. kind_of_data(text, low, high) gives back "valid", "invalid" or "erroneous". Text that is not a whole number is erroneous. Use text.isdigit(). This simple check also calls a negative number such as "-1" erroneous.
  2. expected_result(text, low, high) gives back "Accepted" for valid data and "Rejected" for the rest.
  3. data_for_test(low, high) gives back six pieces of test data as text. They are: below the low edge, the low edge, the middle, the high edge, above the high edge, and "abc". For the middle use (low + high) // 2. This adds them, divides by 2 and drops any decimal part.
  4. count_failed(expected, actual) counts the places where two lists of results are different.

Press Run Tests to check.

Code: python
def kind_of_data(text, low, high):
    # A field takes a whole number from low to high, typed as text.
    # "valid"     a whole number from low to high (both included)
    # "invalid"   a whole number outside that range
    # "erroneous" text that is not a whole number, such as "abc" or "5.5" or ""
    # Use text.isdigit() to tell if the text is a whole number.
    return None


def expected_result(text, low, high):
    # "Accepted" for valid data. "Rejected" for everything else.
    return None


def data_for_test(low, high):
    # Give back a list of 6 pieces of test data, all as text, in this order:
    # low - 1, low, the middle (low + high) // 2, high, high + 1, "abc"
    # For 13 and 19 that is ["12", "13", "16", "19", "20", "abc"].
    return None


def count_failed(expected, actual):
    # expected and actual are two lists of "Accepted" and "Rejected", the same length.
    # Give back how many places are different. These are the tests that failed.
    return None

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

Watch: test data and test plans

Press Play on the short film below. It sorts test data for a mark into its kinds. Then it writes a test plan, runs it and finds a bug. Last, it shows how erroneous data is different from invalid data. Watch which test finds the bug.

Film: test data and test plans

Test data and test plans

Every scene, as text

  1. Four kinds of test data for a mark that must be a whole number from 0 to 100. 55 is valid data, the right kind inside the limits, so it is accepted. 150 is invalid data, the right kind outside the limits, so it is rejected. Boundary data is the lowest and highest valid marks, 0 and 100, accepted, and the first marks outside them, -1 and 101, rejected: so 101 is boundary data and invalid too. Last, abc is erroneous data, the wrong kind, rejected.
  2. A test plan is written before any test runs: each test, its purpose, its test data and its expected result, decided before the test. The lesson's plan for the mark: test 1 is 55, in the middle, accepted; tests 2 and 3 are the edges, 0 and 100, accepted; tests 4 and 5 are just outside, 101 and -1, rejected; test 6 is abc, text instead of a number, rejected.
  3. Run the tests and fill in the actual results. This is the lesson's "Try it: record the actual results" with <= 100 changed to < 100, as it asks. Tests 1 and 2 pass. Test 3, 100, is rejected where it should be accepted: the actual result is not the expected one, so the test fails and a bug is found, by the top edge alone. Tests 4, 5 and 6 pass.
  4. Myth (false): erroneous data is the right kind of data but outside the limits. That is invalid data; erroneous is the wrong kind. The task's kind_of_data asks about the kind first: text that is not a whole number gives "erroneous". Only a whole number is checked against the limits, low to high. So kind_of_data("150", 0, 100) prints invalid and kind_of_data("abc", 0, 100) prints erroneous.
  5. The cure: ask about the kind first, then the limits. Not a whole number, like abc: erroneous. A whole number outside 0 to 100, like 150: invalid. A whole number from 0 to 100, like 55: valid. Boundary data is also one of these three: 101, just outside, is invalid, and 100, on the edge, is valid.

Key words crossword

Have a go

Loading…

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

Exit quiz

Have a go

Exit quiz

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

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.