Skip to content
SPM Tuition
Computer Science · Algorithm reasoning and test design

Choosing test data from one specification

You are asked to test a program and cannot tell which inputs are worth trying.

Good test data comes from the specification, not from guessing. Read the rule, find its edges, and choose one input for each kind: normal, boundary and invalid.

This lesson is part of algorithm reasoning and test design. The general idea is also introduced in testing normal, boundary and invalid inputs.

What is the specification?

A school canteen app asks for the number of drink cups a class wants to order. The rule reads: the order must be a whole number from 1 to 40 inclusive, and the program outputs ACCEPTED or REJECTED.

Two phrases carry all the information: “whole number” and “from 1 to 40 inclusive”. Underline them before choosing any data.

How do you find the categories?

Work through the wording in three steps.

  1. Normal: a value well inside the range, such as 18.
  2. Boundary: the exact edges, 1 and 40, then the first values outside them, 0 and 41.
  3. Invalid: values of the wrong kind or plainly impossible, such as 2.5, −7 and the word “ten”.

The word “inclusive” is the trigger. It tells you 1 and 40 must be accepted, so they are valid boundary values rather than invalid ones.

What does the finished test table look like?

Input Category Expected output Reason
18 Normal ACCEPTED Inside the range
1 Boundary ACCEPTED Lowest allowed, inclusive
40 Boundary ACCEPTED Highest allowed, inclusive
0 Boundary (just outside) REJECTED One below the minimum
41 Boundary (just outside) REJECTED One above the maximum
2.5 Invalid REJECTED Not a whole number
−7 Invalid REJECTED Negative quantity
ten Invalid REJECTED Not a number

Fill the expected column from the specification alone. Only then run the program and compare.

What mistake does this catch?

Suppose the program says IF cups > 1 AND cups < 40 THEN. The normal value 18 passes, so a student who tests one input believes the program works.

The boundary rows expose it. The input 1 gives REJECTED and 40 gives REJECTED, yet the table expects ACCEPTED. Changing the operators to >= and <= fixes both.

Check yourself

A school hall booking form accepts a seat number from 1 to 120 inclusive, whole numbers only. Choose six test inputs with their categories and expected results.

Answer

One good set is:

  • 60, normal, ACCEPTED
  • 1, boundary, ACCEPTED
  • 120, boundary, ACCEPTED
  • 0, just outside, REJECTED
  • 121, just outside, REJECTED
  • 7.5, invalid, REJECTED

Any invalid entry works for the last row, such as −3 or “abc”. The key is that both edges and both values just outside them appear.

What to study next

Next, see how two different algorithms can be judged against the same rule in comparing two algorithms against one contract. Log the test rows you forget using the mistake log and paper-error review.

For a teacher to check your own test plans, see online one-to-one Computer Science tuition.

Common questions

What is the difference between boundary and invalid data?

Boundary data sits exactly on the edge of what is allowed, such as the smallest or largest valid value. Invalid data is outside what the program should accept at all. Boundary values are valid, and invalid values should be rejected.

How many test cases are enough?

Enough to cover each category and each boundary once. For a rule such as a mark from 0 to 100, that is at least one normal value, both ends, one value just outside each end, and one wrong data type.

Do I need to write the expected output before running the test?

Yes. Decide the expected result from the specification first. If you copy the output the program gives, you are only recording what it does, which proves nothing about whether it is correct.

Why test a value just outside the boundary?

Faults often sit on the comparison operator, such as > instead of >=. The value on the edge and the value just beyond it are the two inputs that separate a correct operator from a wrong one.

If you run out of test ideas after two inputs, a one-to-one Computer Science teacher can go through your specification with you and help you find the boundaries you missed.

  • Online one-to-one lessons for your child with an experienced teacher.
  • Your first class is a one-hour trial, from RM50. The fee is agreed before you book.
  • Happy with the teacher? Continue with lessons of about 1.5 hours. If not, ask for another teacher.