Two hundred tests before lunch
A team has 200 tests for its cleaning tool. After every change they must run all 200. By hand, that takes two days. A person gets bored and misses one.
A computer can run all 200 in a minute, the same way every time.
Key words
| Word | What it means |
|---|---|
| Automation | getting a computer to do repeated steps with no person pressing each key |
| Macro | a recorded set of steps in a program such as a spreadsheet, which can be played back |
| Script | a short program written to do a repeated job |
| Test case | one input with the answer you expect |
| Regression testing | running old tests again after a change |
| Maintenance | keeping a script working as the thing it tests changes |
The cells students fill in are left blank in this preview.
By the end of this lesson
Note
I can say what macros and scripts are for, when they suit automation, and write a script that runs test cases.
Starter
Have a go
Starter
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
Macros and scripts compared
| Macro | Script | |
|---|---|---|
| What it is | Recorded steps played back | A program you write |
| Where it lives | Inside a spreadsheet or office program | In a file run by a language such as Python |
| Good at | Repeating clicks and menu steps | Repeats, decisions and many files |
| Skill needed | Little: you record what you do | Some programming |
| Weak at | Anything the recorder cannot see | Takes time to write and fix |
The cells students fill in are left blank in this preview.
No macro recorder here
Important
This platform has no spreadsheet and no macro recorder, so macros are explained and not tried. Scripts you can write, and you do that below.
Why automate, and when not to
Automate a job that is repeated, boring and exact. Tests that run after every change suit it well. A script never gets tired and does the same steps every time.
Do not automate what you will run once, or what needs a human opinion, such as whether a screen is easy to read. A script also needs fixing when the thing it tests changes.
Try it: a small test script
def double(n):
return n * 2
cases = [[1, 2], [3, 6], [4, 9]]
number = 1
for case in cases:
got = double(case[0])
if got == case[1]:
print("PASS", number)
else:
print("FAIL", number, "expected", case[1], "got", got)
number = number + 1
# Fix the third case so every line says PASS.
Check
Have a go
Check
4 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.