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

Preview

Closed box, open box and AI testing

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

45 minutes

A lift with a button

You press a lift button. The lift comes. You do not know how the lift works inside.

A lift engineer can open the panel and look at the inside. That person tests in a different way.

We test software in both ways: from outside, and from inside.

Key words

WordWhat it meansExample
Closed box testingTesting with no view of the code. We only give inputs and check outputs.Press Buy and see the receipt
Open box testingTesting with the code in view. Also called structural testing.Test every if and else
Structural testingAnother name for open box testing: it follows the structure of the code.Test every path
PathOne route through the code.The code inside one if
Automatic testingA program runs the tests for you.Run 500 checks in a minute
Manual testingA person runs the tests by hand.Press each button
AI toolA program that can write text or code when you ask it.A chat assistant
RequirementSomething the product must do.Users can log in
FunctionA named piece of code that does one job.grade(score)
Unit testA test of one small part, such as one function.Test the grade function
Test caseOne input and the answer we expect.Input 3, expect 6

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

Closed box and open box

Closed boxOpen box
What the tester seesOnly inputs and outputsThe code inside
Who often does itTesters, users, the clientThe developer
How tests are chosenFrom the requirementsFrom the paths in the code
ExampleType 45 and check the grade says nearSee the line if score >= 40 and make sure a test reaches it
Weak pointCannot see code that is never reachedCan miss a requirement the code forgot

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

Try it: find the paths

Code: python
def grade(score):
    if score < 0 or score > 100:
        return "invalid"
    if score >= 50:
        return "pass"
    if score >= 40:
        return "near"
    return "fail"

for score in [75, 45, 10, 150]:
    print(score, grade(score))

# There are 4 paths. Did the four scores above reach all of them?
# (>= means "is bigger than or equal to")

Open box finds the limits

data-callouts.tip.label

In the code, >= means "is bigger than or equal to". So score >= 50 means 50 or more. Test 49, 50 and 51. Mistakes often hide where an if changes the answer.

Manual and automatic testing

Manual testing: a person runs the test. Good for new things, how a page feels and odd ideas.

Automatic testing: a program runs the tests. Good for tests you repeat, such as after every change. A computer does not get bored and does not forget a step.

Using AI tools to help

An AI tool can help you test. You can ask it for test ideas, for odd inputs, or to write the first version of unit tests.

It is fast. But it can be wrong, and it does not know your requirements. You must read and run what it writes.

Using an AI tool: ask, read, run, add

StepWhat you doExample
AskType a clear prompt (the words you give the AI)Write 5 test cases for grade(score). 50 or more is a pass. Scores go from 0 to 100.
ReadCheck each test against the ruleIs the expected answer right for 50?
RunRun every test. Fix any test that is wrongThe AI wrote 49 as a pass. That is wrong.
AddAdd the tests the AI missedAdd -1 and 101, which are not allowed.

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

Rules for AI help

data-callouts.warning.label

Check every test the AI writes. Do not paste passwords or private data into it. You are responsible for the result, not the AI.

Quick check: AI and testing

Have a go

Quick check: AI and testing

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.

The lesson goes on

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