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

Preview

Testing parts, then the whole

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

50 minutes

Check the brakes first

A bike builder checks the brakes, the gears and the chain one by one. Only then does she put the bike together.

Imagine she tested only the finished bike. A bad brake would be hard to find. Software is built the same way. You test the small parts first, then bigger and bigger parts.

Key words

WordWhat it meansExample
ComponentOne part of a solution, such as a function, a device or a screen.
InterfaceThe place where two parts meet and pass data.a screen and a database
Unit testA test of one small part on its own.
Integration testA test that checks joined parts work together.
System testA test of the whole system against its requirements.
Acceptance testThe customer tests the product and decides to accept it.
Boundary testA test with values on the edges of what is allowed.
Concept testA test of an idea or a design before it is built.
RequirementSomething the solution must do.
FunctionA named piece of code that does a job.
PrototypeA simple early model of a product, used to try out an idea.
DatabaseAn organised store of data that programs can read and change.

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

Five things you test

PartWhat it isAn example test
SoftwareThe code, such as one functionDoes the fare function give 2.50 for an adult?
HardwareThe devices and partsDoes the card reader read a card?
DataFiles and databasesIs every price in the file a number?
InterfacesWhere two parts meetDoes the screen send the right data to the database?
Resulting serviceThe finished productCan a customer buy a ticket from start to end?

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

Quick check: which part?

Have a go

Quick check: which part?

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

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

Why test the parts first?

A bug in a small part is easy to find. You know which part to look at.

A bug in a finished product could be anywhere. Fixing a bug early is cheaper than fixing it late. And when every part works, you can trust them when they are joined.

Six testing methods

MethodPurposeWhen it is used
Concept testingFind out if an idea or design is worth buildingAt the start, with a sketch or a prototype
Unit testingCheck one small part on its ownEvery time a part is written or changed
Boundary testingCheck the edges of the allowed valuesWhen a part has a limit, such as an age range
Integration testingCheck that joined parts work togetherWhen parts are put together
System testingCheck the whole system against the requirementsWhen all parts are joined
Acceptance testingThe customer checks it does what they needAt the end, before they accept the product

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

Try it: a unit test

Code: python
def fare(age):
    if age < 16:
        return 1.0
    return 2.5

# A unit test checks one small part on its own.
assert fare(10) == 1.0
assert fare(40) == 2.5
print("Both unit tests passed")

# Add a third test: assert fare(16) == 2.5
# Then break the function and see the test fail.

Try it: boundary tests

Code: python
def is_teenager(age):
    return age >= 13 and age <= 19

# Test the edges: one below, on the edge, on the edge, one above.
for age in [12, 13, 19, 20]:
    print(age, is_teenager(age))

# Change >= 13 to > 13. Which age now gives the wrong answer?

The lesson goes on

7 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.