Comet finishes Beacon's water alert and runs it by hand on one reading: 50. No alert appears, which is correct.
"It works!" she says. "Ship it to mission control."
Wren reads the requirement aloud. "Show an alert when the water level is below 30." He looks up. "What do you notice?"
"It worked," Comet says. "For one reading."
Nova hovers beside the code and dims every number except 0, 30 and 100. "Would you like a hint?" she asks. "Try the edges."
Comet sighs, then grabs a pencil. "Fine. Let's build a real test plan."
Wren slides the requirement across to you. "You are the developer. What should we test first?"
This week asks: how do we know a program really works, and how do we help others fix it?
Testing uses defined inputs to check that an algorithm or program produces the expected outcomes.
Programmers use the test results to revise their algorithms or programs.
A program needs to work for a variety of inputs and situations, not just one. The program requirements tell you which inputs to test.
BEACON ALERT, VERSION 1
IF (waterLevel ≤ 30)
{
DISPLAY("The tomatoes need water")
} Good test inputs show the different expected outcomes. They sit at or just beyond the extremes: the minimum and the maximum.
Beacon's readings run from 0 to 100. So the test plan includes 0 and 100, and also -1 and 101, just beyond them.
The crew also tests right at the alert line, 29 and 30, where the outcome should change.
| Test input | Why test it | Expected outcome |
|---|---|---|
| -1 | Just below the minimum | Check the sensor |
| 0 | The minimum | The tomatoes need water |
| 29 | Just below the alert line | The tomatoes need water |
| 30 | Right at the alert line | No message |
| 50 | A middle value | No message |
| 100 | The maximum | No message |
| 101 | Just beyond the maximum | Check the sensor |
| Statement | True or false? |
|---|---|
| One passing test proves a program works. | ? |
| Good test inputs include values at and just beyond the minimum and maximum. | ? |
| Requirements help you choose which inputs to test. | ? |
| You should write the expected outcome after you see what the program does. | ? |
Good testing, developer. Tomorrow you will meet four kinds of bugs.