Chapters & contents Lesson 1 of 12
3 min read
Software testingExpanded reading

Test behavior at the boundaries that matter

Turn a requirement into examples that can expose a real defect.

What you’ll learn

  • Choose normal, boundary, and invalid examples from a contract
  • Separate a pure rule from external dependencies
  • Explain why a passing test suite is evidence rather than proof

Write the rule in observable language

Consider a progress function that accepts completed lesson count and total published lesson count. Define its contract before choosing a test framework: zero completed out of four means zero percent, two out of four means fifty percent, and four out of four means one hundred percent. Decide what should happen when the total is zero or completed exceeds total. A test cannot reliably identify the intended behavior when the requirement is still an unstated assumption in the author’s head.

Use boundaries to challenge the implementation

For a function defined on valid counts with a positive total, test zero completed, one completed, exactly all completed, and a total of one. Separately test invalid negative values and a zero total according to the chosen contract. An implementation that divides total by completed might accidentally pass a case where both values are equal, yet fail at zero. Select examples that distinguish likely wrong implementations. Repeating the same comfortable middle case with different numbers adds less evidence than testing a meaningful edge.

Separate calculation from communication

A pure percentage calculation can be tested without a database, a browser, or a network. Saving the result needs different evidence: an integration test can verify that a learner’s progress is stored under the correct account and that failures are reported correctly. A browser test can check that the visible progress changes after a successful save. Give each test a clear reason to exist. Thousands of tiny tests do not replace one missing check at an important system boundary.

Control the sources of nondeterminism

A password-reset expiry check depends on time. Pass the current time into the rule, or use the framework’s supported clock control, rather than waiting in real time for the token to expire. Similarly, replace a remote service with a controlled test double when testing the caller’s error behavior, then test the real integration separately. A test double proves behavior against the simulated contract; it cannot prove the live service currently implements that contract. Keep that distinction visible when describing test coverage.

Read failures as diagnostic evidence

A useful test name describes the condition and expected behavior. Its failure should show expected and actual values, with enough context to reproduce the issue. If a regression is fixed, keep a focused example that would fail under the old behavior. Also review what the suite does not exercise: concurrency, unusual encodings, resource limits, and deployment configuration can matter. Passing tests increase confidence within their scope. They do not remove the need to inspect requirements, code, and real operational behavior.

Try it yourself

Write three test cases for percentage(completed, total) that expose more than the single example percentage(2, 4) = 50. State your policy for total = 0.

Show a possible solution

Examples include percentage(0, 4) = 0, percentage(4, 4) = 100, and percentage(1, 1) = 100. Choose and document a zero-total policy, such as raising a validation error, then test that policy explicitly. Add invalid-count cases as the contract requires.

Check your understanding

Try 11 questions across software testing. Read each explanation and revisit anything that needs another pass.

Practise this subject

Go to the source

Use these primary references to check details and explore the topic further.

Saved in this browser. Signed-in progress syncs to your account.