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

Free lesson

OS 7.3 (2 of 2): The test plan and re-testing

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

A test with no notes

A tester finds a bug on Monday. A programmer fixes it on Tuesday. On Wednesday nobody remembers what the tester did, with which data, or what the right answer was.

A test plan is the answer. It is a table that says what to test, how, and what should happen.

Key words

WordWhat it meansExample
Test planA table of the tests: what to do and what should happen.One row for each test
PurposeWhat the test is for.Check that a 16-year-old is accepted
Pre-requisiteWhat must be true before the test can start.The user is logged in
Expected resultWhat should happen if the software is right.The form accepts the age
Actual resultWhat really happened when you ran the test.The form refused the age
Re-testRunning a failed test again after the fix.Run test 3 again
Regression testingRunning old tests again to check a change broke nothing else.Run all 12 tests again
Test dataThe values you use in a test.16

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

What each column holds, and when

ColumnWhat you writeWhen you fill it in
Test numberA number so you can find the testBefore
PurposeWhat the test checksBefore
Pre-requisiteWhat must be true firstBefore
Test dataThe values you will useBefore
Expected resultWhat should happenBefore
Actual resultWhat did happenAfter you run it
Pass or failDo expected and actual match?After you run it
Changes madeWhat you fixedAfter a fail
Re-test resultPass or fail after the fix, plus the old testsAfter the fix

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

Match each column to its meaning

Have a go

Loading…

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

Worked example: a filled-in plan

NoPurposePre-requisiteTest dataExpectedActualResultChange madeRe-test
1A normal age is acceptedForm is open17AcceptedAcceptedPassNonePass
2Lowest valid age is acceptedForm is open16AcceptedRefusedFailChanged age > 16 (bigger than 16) to age >= 16 (16 or more)Pass
3Just below the range is refusedForm is open15RefusedRefusedPassNonePass
4Text is refusedForm is openabcError messageError messagePassNonePass

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

Row 2 shows a re-test and regression

Note

Test 2 failed. The programmer made a change. Then the tester ran test 2 again, and also tests 1, 3 and 4. Running tests 1, 3 and 4 again is regression testing.

Test, fix and test again

flowchart TD
  plan[Write the plan with expected results] --> run[Run the tests]
  run --> record[Write the actual result]
  record --> ok{Did it pass?}
  ok -->|yes| done[Done]
  ok -->|no| fix[Fix the code and write the change]
  fix --> retest[Re-test, then regression test everything]
  retest --> record

Check: filling in the plan

Have a go

Check: filling in 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

Bug hunt: fix the ticket machine

The ticket machine code has four bugs. The test plan found them. Read the rules at the top of the starter, then fix the code. After each fix, press Run Tests again. All four tests must pass at the end. A fix that breaks a test you passed before is a regression: find and fix that too.

Code: python
# A bus ticket machine. The plan says:
#   Under 5: free (0).  Age 5 to 15: child fare 1.0.  Age 16 and over: adult fare 2.5.
#   A student aged 16 or over pays 1.5.  A child who is a student still pays 1.0.
#   An age below 0 is a mistake: use raise ValueError(...) to stop with an error.
# The code below has FOUR bugs. The tests in the plan found them. Fix them.

def ticket_price(age, is_student=False):
    if age <= 5:
        return 0
    if age < 15:
        return 1.0
    if is_student:
        return 2.5
    return 2.5

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

Run all the old tests after a fix

Many people think a fix only touches the bug it fixes. A fix can break something else. A programmer fixes the free ticket rule. By mistake, the child fare changes too.

Nobody notices, because only the free ticket test was run again. So after every change, run all the old tests. The hidden tests in the bug hunt do this for you.

Write a test plan

A website needs a password of 8 to 20 characters. Write a test plan with 6 rows. Use these columns: number, purpose, pre-requisite, test data, expected result. Include normal, valid extreme, invalid extreme and erroneous data. Leave the actual result empty, because you have no program to run yet.

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

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.