A quiet Tuesday and Black Friday
A shop website works well on a quiet Tuesday. On Black Friday 20,000 people arrive at once.
The site is slow. Then it stops. The tests on Tuesday never saw this. Different problems need different kinds of testing. In this lesson you meet six more groups of methods.
Key words
| Word | What it means |
|---|---|
| Performance test | Checks how fast the system is and how much memory it uses. |
| Load test | Checks the system with the number of users you expect on a busy day. |
| Stress test | Pushes the system past its limit to see how and when it breaks. |
| Usability test | Real people try the product. You watch how easy it is to use. |
| Regression test | Runs the old tests again after a change, to check nothing broke. |
| Closed box test | You test inputs and outputs. You cannot see the code. |
| Open box test | You can see the code and choose tests that use every path. |
| Automation | Letting a computer run the tests for you. |
| Macro | A recorded list of actions that a program can repeat. |
| Script | A small program that runs a job, such as running tests. |
| Function | A named piece of code that does a job. |
| Unit test | A test of one small part on its own. |
| Prototype | A simple early model of a product, used to try out an idea. |
The cells students fill in are left blank in this preview.
Six more groups of testing methods
| Method | Purpose | When it is used |
|---|---|---|
| Performance | Is it fast enough, and does it use too much memory? | When speed matters, and after big changes |
| Usability | Can real people use it easily? | On a prototype and on the finished product |
| Regression | Did a change break something that worked? | After every change or fix |
| Load | Does it cope with the expected number of users? | Before a busy time, such as a sale |
| Stress | What happens when it is pushed past its limit? | To find the breaking point and see how it fails |
| Closed box and open box | Test with no view of the code, or with the code in view | Closed: acceptance and system tests. Open: unit tests |
The cells students fill in are left blank in this preview.
Match the situation to the method
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Closed box and open box
In closed box testing you treat the program like a sealed box. You put data in and check what comes out. You do not care how it works inside.
In open box testing you can see the code. You choose tests so that every path is used: every if, every elif and every else.
Try it: cover every path
def fare(age):
if age < 5:
return 0.0
elif age < 16:
return 1.0
else:
return 2.5
# This function has three paths, so an open box tester needs three tests.
assert fare(3) == 0.0
assert fare(10) == 1.0
assert fare(30) == 2.5
print("All three paths tested")
# Delete the last assert. Which path is now never tested?
Make a free account to save your work and track your progress.
Benefits and drawbacks
| Method | Benefit | Drawback |
|---|---|---|
| Performance | Finds slow parts before users do | Needs a realistic machine and data |
| Usability | Shows real problems that developers miss | Slow and costly: needs real people |
| Regression | Catches broken old features | The set of tests grows and takes time to run |
| Load and stress | Finds the limit before a busy day | Needs special tools and a copy of the live system |
| Closed box | Tests like a real user, and the code does not guide the tests | Some paths in the code may never be tried |
| Open box | Can test every path in the code | The tester needs to understand the code |
The cells students fill in are left blank in this preview.
Quick check: which method?
Have a go
Quick check: which method?
4 questionsLet the computer do the testing
Running the same tests by hand is slow and boring. People make mistakes when they are bored.
Automation lets a computer run tests again and again, the same way every time. It is very good for regression tests: run all the tests after each change, even at night.
Three ways to automate
| Tool | What it is | Example | Drawback |
|---|---|---|---|
| Macro | Records the actions of a user and plays them back | Record the steps in a spreadsheet and repeat them | Breaks when the screen changes |
| Script | A small program that runs tests and reports | A Python file that calls functions and checks answers | Somebody must write and keep it up to date |
| Functional testing tool | Software that clicks through an app and checks the results | A tool that opens a web page, types and presses buttons | Takes time to learn and set up |
The cells students fill in are left blank in this preview.
Try it: a test script
def double(n):
return n * 2
arguments = [2, 5, 3]
expected = [4, 10, 7]
for i in range(len(arguments)):
answer = double(arguments[i])
if answer == expected[i]:
print("PASS", arguments[i])
else:
print("FAIL", arguments[i], "expected", expected[i], "got", answer)
# One test is wrong on purpose. Which one?
Make a free account to save your work and track your progress.
Try it: a performance test
from datetime import datetime
start = datetime.now()
total = 0
for number in range(1000000):
total = total + number
end = datetime.now()
print("Total:", total)
print("Time taken:", end - start)
# Change 1000000 to 10000000. How does the time change?
Make a free account to save your work and track your progress.
Extra: Try it: find the breaking point
capacity = 5
served = 0
for user in range(1, 13):
if served < capacity:
served = served + 1
print("User", user, "served")
else:
print("User", user, "refused: the server is full")
print("It broke at user", capacity + 1)
# A stress test keeps adding users until something fails.
# Change capacity to 8. Where is the breaking point now?
Make a free account to save your work and track your progress.
Quick check: a regression test
Have a go
Quick check: a regression test
3 questionsYour turn: four test scripts
Write four small automation scripts.
count_passes(actual, expected)compares two lists and gives back how many answers match.regression_check(old_answers, new_answers)gives back a list of the positions where an answer has changed.fast_enough(seconds_taken, limit_seconds)gives back True if the time was under the limit. Exactly on the limit is not fast enough.load_report(replies)counts how many users got "ok".
Press Run Tests to check.
def count_passes(actual, expected):
# A test script. actual and expected are two lists of the same length.
# Compare the items in the same position. Give back how many are equal.
return None
def regression_check(old_answers, new_answers):
# A regression test. old_answers were right last week. new_answers are from today.
# Give back a list of the positions (starting at 0) where the answer is now DIFFERENT.
return None
def fast_enough(seconds_taken, limit_seconds):
# A performance test. Give back True if the time taken was less than the limit.
return None
def load_report(replies):
# A load test. replies is a list of "ok" and "error", one for each user.
# Give back how many users got "ok".
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Watch: more testing methods and automation
Press Play on the short film below. It tests the fare function on every path and runs a test script. Then it shows a regression test finding what a change broke, and asks what an automated test cannot judge. Watch what each test compares.
Film: more testing methods and automation
More testing methods and automation
Every scene, as text
- Open box testing: you can see the code, so you choose tests that use every path. In closed box testing you cannot see it, and only check what comes out. The lesson's fare function has three paths, so it needs three tests: fare(3) takes the if, fare(10) the elif and fare(30) the else. All three asserts pass, so it prints All three paths tested.
- Automation: a test script lets the computer run the tests, the same way every time. It calls double on each argument and compares the answer with the expected one. It prints PASS 2 and PASS 5, then FAIL 3 expected 7 got 6: double(3) gives 6, and the expected 7 is the test that is wrong on purpose.
- A regression test runs the old tests again after a change, to check nothing broke, and a script is very good at it. The task's regression_check compares the old answers, right last week, with the new answers from today, position by position: regression_check([2, 4, 6, 8], [2, 4, 0, 0]) prints [2, 3], so the change broke the answers at positions 2 and 3, which used to work.
- Myth (false): automated tests are good at judging if a page looks pleasant. A test script such as the task's count_passes can only compare each answer with an expected one: count_passes([4, 10, 6], [4, 10, 7]) prints 2, as 4 and 10 match and 6 is not 7. How pleasant a page looks has no expected answer to compare.
- The cure: that needs a person. In a usability test real people try the product, and you watch how easy it is to use. A test repeated many times, such as a regression test, is the one to automate, but somebody must write the script and keep it up to date.
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