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
| Word | What it means | Example |
|---|---|---|
| Component | One part of a solution, such as a function, a device or a screen. | |
| Interface | The place where two parts meet and pass data. | a screen and a database |
| Unit test | A test of one small part on its own. | |
| Integration test | A test that checks joined parts work together. | |
| System test | A test of the whole system against its requirements. | |
| Acceptance test | The customer tests the product and decides to accept it. | |
| Boundary test | A test with values on the edges of what is allowed. | |
| Concept test | A test of an idea or a design before it is built. | |
| Requirement | Something the solution must do. | |
| Function | A named piece of code that does a job. | |
| Prototype | A simple early model of a product, used to try out an idea. | |
| Database | An 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
| Part | What it is | An example test |
|---|---|---|
| Software | The code, such as one function | Does the fare function give 2.50 for an adult? |
| Hardware | The devices and parts | Does the card reader read a card? |
| Data | Files and databases | Is every price in the file a number? |
| Interfaces | Where two parts meet | Does the screen send the right data to the database? |
| Resulting service | The finished product | Can 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 questionsYour 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
| Method | Purpose | When it is used |
|---|---|---|
| Concept testing | Find out if an idea or design is worth building | At the start, with a sketch or a prototype |
| Unit testing | Check one small part on its own | Every time a part is written or changed |
| Boundary testing | Check the edges of the allowed values | When a part has a limit, such as an age range |
| Integration testing | Check that joined parts work together | When parts are put together |
| System testing | Check the whole system against the requirements | When all parts are joined |
| Acceptance testing | The customer checks it does what they need | At the end, before they accept the product |
The cells students fill in are left blank in this preview.
Try it: a unit test
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
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?