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.
Software is tested in both ways: from outside, and from inside.
Key words
| Word | What it means | Example |
|---|---|---|
| Closed box testing | Testing inputs and outputs with no view of the code. | Press Buy and see the receipt |
| Open box testing | Testing with the code in view. | Test every if and else |
| Structural testing | Another name for open box testing. | Test every path |
| Path | One route through the code. | The code inside one if |
| Automatic testing | A program running the tests for you. | Run 500 checks in a minute |
| Manual testing | A person running 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. | Test the grade function |
| Test case | One input and the answer you expect. | Input 3, expect 6 |
The cells students fill in are left blank in this preview.
Closed box tests outside, open box inside
| 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.
Match each word to its meaning
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
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")
Make a free account to save your work and track your progress.
Test either side of each if
Tip
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.
Reach every path
You can see the grade function in the starter. This is open box testing. Fill in inputs_for_every_path. It gives a list of scores. Together they must reach all four paths: invalid, pass, near and fail. Also include 50 and 40, where the answer changes. Include one score below 0 and one score above 100. Press Run Tests.
# This is the function we test. You can see all of it, so this is open box testing.
#
# def grade(score):
# if score < 0 or score > 100:
# return "invalid"
# if score >= 50:
# return "pass"
# if score >= 40:
# return "near"
# return "fail"
#
# Give back a list of scores. Together they must make the function
# go down EVERY path: invalid, pass, near and fail.
# Also test the limits 50 and 40, where the answer changes.
# Include one score below 0 and one score above 100.
def inputs_for_every_path():
return []
Make a free account to save your work, or press Start lab to work through the whole lesson.
People explore, programs repeat
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.
Build a test runner
Write a tiny automatic test runner. A case is a pair: the input and the answer you expect. failed_cases calls the function for each case and gives back the cases that did not match. all_pass says True when nothing failed. Press Run Tests.
# An automatic test runner. A case is a pair: (input, expected answer).
# For example: (3, 6) means "when the input is 3 we expect 6".
# For one case: case[0] is the input and case[1] is the expected answer.
def failed_cases(function, cases):
# Call function with each input. Give back a list of the cases where
# the answer was not the expected one. Keep the order.
return []
def all_pass(function, cases):
# True if no case failed.
return False
Make a free account to save your work, or press Start lab to work through the whole lesson.
An AI tool can suggest tests
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.
You are responsible, not the AI
Warning
Many people think tests from an AI tool are already correct. They can be wrong, so check every test the AI writes. Do not paste passwords or private data into it. You are responsible for the result, not the AI.
Check: AI and testing
Have a go
Check: AI and testing
3 questionsKey words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Final check
Have a go