intermediate24 min

Boundary-Value Analysis (Lab)

A hands-on lab: target the exact edges of a valid range, where off-by-one errors overwhelmingly cluster in real systems.

What you'll learn

  • Identify the boundary values of a given valid range
  • Design test cases at, just below, and just above each boundary
  • Explain why boundaries are disproportionately likely to contain defects

Prerequisites

Explanation

Equivalence partitioning tells you which classes exist and to test one representative from each. Boundary-value analysis is a refinement of exactly where within a class to place that representative — and it makes one sharp, well-evidenced claim: defects cluster overwhelmingly at the edges of a range, not in the comfortable middle.

The reason is almost always the same programming mistake: a comparison operator that's one character off. age >= 18 and age > 18 look nearly identical and produce completely different behavior for exactly one input: 18 itself. A test suite that only checks age 25 and age 10 will never notice this bug. A test suite that checks age 17, 18, and 19 will catch it immediately, because 18 is the boundary and 17/19 are the values immediately adjacent to it.

For a range with a minimum and maximum — say, a discount code length of 6 to 10 characters — boundary-value analysis produces test values at both ends: just below the minimum (5), at the minimum (6), just above the minimum (7), just below the maximum (9), at the maximum (10), and just above the maximum (11). That's six values total for one range, chosen not by feel but by a rule: for every boundary, test the boundary itself and its immediate neighbor on each side.

In practice, testers often combine the two techniques rather than using six separate values: the boundary value is the representative chosen for its equivalence class, and the "just outside" value is the representative for the neighboring invalid class. This is efficient and is exactly what real test plans do — equivalence partitioning decides which classes need a representative, boundary-value analysis decides which specific value makes the strongest representative.

Example

A voting-eligibility check with an off-by-one bug that only boundary testing reveals.

// Bug: should be >= 18, but uses > 18
function canVote(age) {
  return age > 18;
}

console.log(canVote(10)); // false -- looks fine
console.log(canVote(30)); // true -- looks fine
console.log(canVote(18)); // false -- WRONG. An 18-year-old should be able to vote.

Try it yourself

Fix the off-by-one bug (change > to >=) and re-run to confirm all three boundary cases now behave correctly.

Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.

Loading editor…

Guided exercise

Guided exercise

A field accepts an integer quantity from 1 to 10. List the six boundary-value test numbers as belowMin, atMin, justAboveMin, justBelowMax, atMax, aboveMax.

Checks: belowMin is correct · atMin is correct · justAboveMin is correct · justBelowMax is correct · atMax is correct · aboveMax is correct

Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.

Loading editor…

Stuck? Get a hint.

Independent exercise

Independent exercise

A password field requires a length from 8 to 20 characters. Write a function boundaryLengths() that returns an array of the six boundary-value lengths in ascending order: [7, 8, 9, 19, 20, 21].

Checks: returns the correct six boundary lengths in order

Code editor. Press Escape then Tab to leave the editor if keyboard focus becomes trapped. Press Control+Shift+M inside the editor to toggle Tab-key focus trapping.

Loading editor…

Stuck? Get a hint.

Common mistakes

  • Only testing the exact minimum and maximum, forgetting the values one step outside each boundary — those are what actually catch off-by-one errors like `>` versus `>=`.
  • Testing far-outside values (like -1000 or 1000000) instead of the immediately adjacent value, which misses the specific comparison-operator bugs boundary analysis targets.
  • Applying boundary-value analysis only to numbers, when it applies equally to string lengths, array sizes, dates, and any other bounded range.

Knowledge check

Knowledge check

1. Why do defects cluster at boundaries more than in the middle of a valid range?
2. For a range with a minimum of 5 and a maximum of 50, how many boundary-value test cases does the technique typically produce?
3. How do equivalence partitioning and boundary-value analysis typically work together in practice?

Takeaway

Boundary-value analysis targets the specific values where off-by-one comparison bugs live — the boundary itself and its immediate neighbors on each side, not the comfortable middle of a range.

Summary

This lab practiced identifying the six boundary-value test cases (below, at, and above each of a range's minimum and maximum) and explained why comparison-operator bugs specifically cluster there.

References

Your notes

Notes save automatically.

Finished this lesson?

Mark it complete to track your progress and schedule a future review.