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

Preview

AC 2.9: Running tests by macro or script

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

60 minutes

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

WordWhat it means
Automationgetting a computer to do repeated steps with no person pressing each key
Macroa recorded set of steps in a program such as a spreadsheet, which can be played back
Scripta short program written to do a repeated job
Test caseone input with the answer you expect
Regression testingrunning old tests again after a change
Maintenancekeeping 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 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.

Macros and scripts compared

MacroScript
What it isRecorded steps played backA program you write
Where it livesInside a spreadsheet or office programIn a file run by a language such as Python
Good atRepeating clicks and menu stepsRepeats, decisions and many files
Skill neededLittle: you record what you doSome programming
Weak atAnything the recorder cannot seeTakes 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

Code: python
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 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.

The lesson goes on

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