Specialty Digest

Global English editionLearners’ Study Dashboard — in development
The Knowledge Library for All

Flashcards: open the module flashcards (end-of-module review with workplace questions).

Online Courses / University Track / Python from Zero

Module 8 · Lesson 3 · Core

Testing the whole program

Test normal, edge and bad data, check counts and widen use in stages.

  • 50 minutes
  • Serves O6
  • Assumes M8.L2

Phase 1: Prepare

Step 1 Warm-up recall

From M8.L2: why keep a working copy?

Private: nothing you type here is sent or stored.

Step 2 Learning goal

By the end of this lesson you can:

  • write a test plan with four kinds of case (Foundation);
  • check counts and outputs (Core);
  • trial the program on small data first (Core).

Phase 2: Teach

Step 3 A familiar example

A new bridge is tested with a light load before it opens, then a heavier one, and only then to traffic. A program is trusted in the same careful steps.

Step 4 Clear explanation

A test plan lists the cases before you run them, with the answer for each worked out by hand.

Kind of testExample for a stock reportWhat it shows
Normalthree valid rowsthe main path works
Edgequantity 0; exactly the reorder levelboundaries are right
Bad inputa blank line; text for a quantity; a missing filefailures are reported, not hidden
Count checkrows read = rows used + rows skippednothing goes missing

Run the whole program on a tiny file you can check by eye. Compare each output line with your hand-worked answer. Check the counts: rows read, rows used, rows skipped.

Each function alone0Small test file1Real data copy2Limited trial first3Widen the ring only when the last one is safe
Test in rings: each function alone, then the whole program on a tiny file, then on real data, then in limited use.

Only when the small file is right, try a copy of real data, never the original. Then use the program in a limited way first, so a fault reaches few people. Real systems have failed when they were switched on for everyone at once after testing only part of the setup, or when test settings were left in place after the test.

Finally, write down what the tests did not cover. Honest limits are part of the test result.

Step 5 Worked example (4 marks)

A stock file has 10 lines; the program reports 7 to reorder, 2 fine and 0 bad. What does the count check say?

  1. Rows read are 10. (1 mark)
  2. Rows used plus skipped are 7 + 2 + 0 = 9. (1 mark)
  3. One row is unaccounted for. (1 mark)
  4. Answer: a row has gone missing; investigate before trusting the report. (1 mark)

Go deeper: the professor's notes

Test the whole setup, not just part of it, and remove test settings before release.
Normal

Typical.

Edge

Boundary.

Bad

Failures.

PlancasesRunsmall fileTrycopy of real dataTriallimited use
Test the whole

Coverage

TestedRisk
one data centre of twounseen fault in the other
bothfault found early

At work: A release

You are about to go live.

  1. Check for test settings.
  2. Start with a limited group.

What a careful practitioner decides. Widen use only when the last stage is safe.

Phase 3: Practise

Step 6 Learner practice (instant-marked)

1. A test plan should be written:

2. Real data should first be tried as:

3. Bad input tests include:

4. A limited trial helps because:

Phase 4: Close

Step 7 Recap

  • Plan the tests: normal, edge, bad input, count check.
  • Work answers out by hand; try a tiny file, then a copy of real data.
  • Trial in a limited way and write down what was not tested.

Step 8 Exit ticket (ungraded)

List four test cases for a program that totals a column of quantities from a file.

Private: nothing you type here is sent or stored.

Step 9 Go further (Extension)

Write the full test plan for your capstone, with expected results.

In industry: HealthCare.gov: not tested for the load

The US Government Accountability Office found that the HealthCare.gov system and its supporting systems were not fully tested before the 1 October 2013 launch, and that capacity had not been planned adequately. A later official said testing had not included performance tests at the volume seen at launch.

Link to this lesson. Test at the load you will really face, and plan capacity from the start.

Source: GAO-15-238 (March 2015); Reuters, 2013

Common mistakes

MistakeWhy it fails
Testing only normal dataAdd edges and bad input.
Testing on the only originalUse a copy.
Leaving test settings in the real programCheck for leftovers before release.

Limits. No plan covers every case; list what is not covered and review it after use.

Flashcards for this lesson (3)

Tap a card to reveal the answer. Read the question, answer it aloud or in writing first, then check yourself against the explanation.

Card 1 of 3 · Why keep a working copy?
Saveafter a passBreaka changeReturnand retry
Working copy

If a change breaks the program, you can return to the last version that passed its tests and try again in a smaller step.

Card 2 of 3 · What goes in a test plan?
NormaltypicalEdgeboundaryBadinput
Test plan

Normal cases, edge cases such as exactly the reorder level, bad input such as a blank line or missing file, and a count check, each with a hand-worked answer.

Card 3 of 3 · How do you check that no rows went missing?
Read12Used9, skipped 2Gap1 missing
Count check

Rows read must equal rows used plus rows skipped. If they do not, some rows have vanished and the report cannot be trusted.

Review with flashcards

Test yourself on this module with workplace flashcards and detailed answers.

Open the module flashcards