AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Plan and test a smart idea

Week 9 · Unit 7.2: Decomposing problems · 3 lessons
3

Test it and trace it

Computing 7: Unit 7.2, pp. 44–81
GoalWrite and complete a test plan with good test data, and use it to find a bug.
New words
test plan · a table of tests that says what to try and what should happentest data · the values used in a testexpected outcome · what should happen, worked out from the plan before the testactual outcome · what really happens when the test is done
Explanation

Testing shows whether a program does what the plan says. A test plan is a table with the test number, the test data, the expected outcome, the actual outcome and a pass or fail. The expected outcome is worked out from the flowchart before the test, never copied from the program. The actual outcome comes from running the program or tracing its code. If they are the same, the test passes. If not, it fails, and you debug. Choose test data carefully: a low value, a high value and values around the threshold, for example one below, exactly on it and one above. Tracing a flowchart with a value is the quickest way to find the expected outcome.

ColumnWhat you write
Testthe number of the test
Test datathe value you try
Expected outcomewhat the flowchart says should happen
Actual outcomewhat really happens
Pass/failpass if the two outcomes match, fail if not
Worked examples
Test dataWhy it is chosen
0the lowest possible value
79just below the threshold
80exactly on the threshold
81just above the threshold
255the highest possible value
Here are the five tests Ravi chooses for his plant shelf (a cross if light_level < 80). Each value has a job.
TestTest dataExpected outcomeActual outcomePass/fail
10crosscrosspass
279crosscrosspass
380ticktickpass
481ticktickpass
5255ticktickpass
Ravi traces the flowchart for each value and writes the expected outcomes before running the program. The actual outcomes match, so every test passes.
TestTest dataExpected outcomeActual outcomePass/fail
10crosscrosspass
279crosscrosspass
380tickcrossfail
481ticktickpass
Now a mistake: the program has if light_level <= 80 instead of < 80. Test 3 fails, because the program shows a cross at exactly 80. The other tests do not show the bug. This is why the value on the threshold is the most important test.
Class activity

Be the tester (no computer). Your partner draws a flowchart for a fish-tank sign: “temperature > 28? yes: cross, no: tick”. You write a test plan with five tests, filling in the expected outcomes first. Your partner then secretly changes the rule to “temperature >= 28”, and reads out the actual outcomes for your five test values. Which test fails? What does it tell you about the bug?

Practice
1
Complete the expected outcomes (tick or cross) for the temperatures 10, 25, 26, 27 and 40 using this flowchart.
Starttemperature >= 26?yesnoshow a tickshow a crossEnd
2
A rule says: show a tick if light_level > 150. Choose three test values that check the boundary and say what each should give.
3
The plan says: tick if the light level is 200 or more. Look at the results. Which test fails, and how should the program be corrected?
TestTest dataExpected outcomeActual outcomePass/fail
1255ticktick?
2200tickcross?
3199crosscross?
40crosscross?
4
Why must the expected outcome be worked out before the program is run?