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
| Word | What it means | Example |
|---|---|---|
| Closed box testing | Testing with no view of the code. We only give inputs and check outputs. | Press Buy and see the receipt |
| Open box testing | Testing with the code in view. Also called structural testing. | Test every if and else |
| Structural testing | Another name for open box testing: it follows the structure of the code. | Test every path |
| Path | One route through the code. | The code inside one if |
| Automatic testing | A program runs the tests for you. | Run 500 checks in a minute |
| Manual testing | A person runs the tests by hand. | Press each button |
| AI tool | A program that can write text or code when you ask it. | A chat assistant |
| Requirement | Something the product must do. | Users can log in |
| Function | A named piece of code that does one job. | grade(score) |
| Unit test | A test of one small part, such as one function. | Test the grade function |
| Test case | One 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 box | Open box | |
|---|---|---|
| What the tester sees | Only inputs and outputs | The code inside |
| Who often does it | Testers, users, the client | The developer |
| How tests are chosen | From the requirements | From the paths in the code |
| Example | Type 45 and check the grade says near | See the line if score >= 40 and make sure a test reaches it |
| Weak point | Cannot see code that is never reached | Can miss a requirement the code forgot |
The cells students fill in are left blank in this preview.
Try it: find the paths
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
| Step | What you do | Example |
|---|---|---|
| Ask | Type 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. |
| Read | Check each test against the rule | Is the expected answer right for 50? |
| Run | Run every test. Fix any test that is wrong | The AI wrote 49 as a pass. That is wrong. |
| Add | Add the tests the AI missed | Add -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 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.