Topic 17

Boundary Value Analysis

Test Design

Partitioning told you where to sample. This topic tells you where the bugs actually live: at the edges. A rule like "1 to 30 nights" fails at 0, 1, 30, and 31 far, far more often than it fails at 15 — and there's a concrete reason. Boundary value analysis — everyone says BVA — is partitioning's sharper sibling: instead of any representative from each group, you deliberately pick the values sitting on and beside the lines. The two techniques are used together on practically every field you will ever test.

Think of a cliff path. The dangerous part isn't the middle of the path — it's the edge. You check your footing where falling is possible, not where it isn't. BVA is exactly that instinct, made systematic.

Why Edges Break

Here's the mechanical reason, and it's worth understanding rather than memorizing. Somewhere in Fernway's code, the rule "up to 30 nights" is written as a comparison — in English, either "reject if nights are greater than 30" or "reject if nights are 30 or greater." Two phrasings, one character apart in code, identical for 15 and for 45 — and opposite for exactly 30. Off-by-one mistakes like this are among the most common in all of programming, and they are invisible everywhere except at the boundary. A middle-of-the-range test can never catch one. A test at exactly 30 catches it every time.

The same goes for the other classic edge mistakes: the rule written against the wrong variable, the "up to" that someone implemented as "up to but not including," the count that starts at 0 in code but at 1 in human heads. All of them concentrate their damage on the line.

The Technique

For each boundary between partitions, test the boundary value and its nearest neighbors. Stay length, valid 1–30: the interesting values are 0, 1, 30, 31 — the last invalid below, the first valid, the last valid, the first invalid above. Four tests, each with a definite expected result (0 refused, 1 accepted, 30 accepted, 31 refused), each capable of exposing a mistake the others can't. Combined with one middle representative from partitioning, the whole field is covered in five aimed tests — and you can say exactly why each exists.

(A note for interview completeness: this two-values-per-edge style is the common one; a three-value variant also tests the value beyond each neighbor — 2 and 29 here. Know it exists; use the two-value style unless a team asks otherwise.)

Stay length 1–30 — where BVA aims
0 · just below
expect: refused
1 · first valid
expect: accepted
30 · last valid
expect: accepted
31 · just above
expect: refused

Boundaries Beyond Numbers

Once you see edges, you see them everywhere — because boundaries aren't a property of numbers, they're a property of rules. The first and last item in a list (does the last search result render? can you delete the only guest?). The empty cart versus one item. The shortest allowed password and the longest allowed name (what happens at exactly the limit — and one past it?). Month-ends and leap days in anything date-shaped. The SUMMER15 minimum: 2 nights, 3 nights — one line, two behaviors, test both sides. Every partition line you drew last topic has two sides, and BVA's standing order is simple: visit both.

Time Boundaries Deserve Fear

And then there's the boundary family that has humbled every booking product ever built: time. Fernway's cancellation rule — free until 48 hours before check-in — is a boundary that moves, recalculated against a check-in moment, across time zones, with a nightly job in the mix (remember the grey-box lesson). The BVA questions write themselves: cancel at 48 hours and one minute — free? At exactly 48:00? At 47:59? And in whose time zone is check-in defined — the traveler's, the property's, the server's? FW-312, the book's signature bug, was exactly a time boundary: a date that shifted by one day for travelers in certain time zones. When you test the 47:59 case at Fernway, it rounds in the traveler's favor — and Petra, shown the result, declares it a feature. Also an outcome: now it's decided, not accidental.

The Standard Field Workup

Put the two techniques together and you get the professional reflex this chapter promised — the answer to the interview classic "how would you test this input field?" First, partitions: valid range, invalid low, invalid high, empty, wrong type. Then, boundaries of each edge: 0, 1, 30, 31. Add one middle representative, and for the stay-length field the complete designed set is: 0, 1, 12, 30, 31, empty, "two" — seven tests, every one with a reason and an expected result. Say those seven values out loud in an interview, with the reasons, and you have visibly separated yourself from every candidate who answered "I'd try some numbers."

And it pays immediately at Fernway: the 0-nights boundary test (the one partitioning alone might have taken at −3) reveals that 0 doesn't error at all — it creates a zero-night booking that charges the cleaning fee. A cousin of FW-341, found at the edge, exactly where the technique said to look.

Common Confusions
  • "Boundary testing means trying extreme values like 999999." Extremes probe one boundary (the far edge of "too big"). The money edges are the rule's own lines: 30 versus 31. A test at a million tells you nothing about an off-by-one at thirty.
  • "If 30 works, 31 will obviously be refused." That's precisely the assumption BVA refuses to make — the two phrasings of the comparison differ exactly there. Test the neighbor; never infer it.
  • "Boundaries only apply to numeric fields." String lengths, list sizes, dates, file sizes, first-and-last items — every rule with a limit has edges. Numbers are just where the technique is easiest to see.
  • "BVA replaces equivalence partitioning." They're a pair: partitioning finds the groups and draws the lines; BVA interrogates the lines. The standard field workup uses both, every time.
Why It Matters
  • Highest bug-yield-per-test of any technique in this book — off-by-one mistakes are among programming's most common, and they're invisible everywhere except where BVA aims.
  • "0, 1, 30, 31" — with reasons — is the interview answer that instantly marks a trained candidate; the full workup (partitions + boundaries) is the take-home-task backbone.
  • Time boundaries — cancellation cutoffs, expiry moments, time zones — are the booking domain's most expensive bug family; the fear this page installed is professional equipment.

Knowledge Check

Why do bugs concentrate at boundaries?

  • Rules become comparisons in code, and the two easy-to-swap phrasings differ only at the line
  • Because extremely large values overload the computer's memory
  • Because users almost never enter middle-of-range values
  • Because developers deliberately skip testing edges

For guests (1–8), which values does two-value BVA prescribe?

  • 2, 4, and 6
  • 0, 1, 8, and 9
  • 0 and 9 only
  • −100 and 100

What makes Fernway's 48-hour cancellation cutoff a especially dangerous boundary?

  • Because 48 is a larger number than most field limits
  • The line moves — computed against a moment, across time zones, with scheduled jobs involved
  • Because the rule was never written down anywhere
  • Because refunds involve money, and money fields have no boundaries

What is the complete designed test set for stay length (1–30), combining partitioning and BVA?

  • 0, 1, 30, 31
  • 5, 10, 15, 20, 25
  • 0, 1, 12, 30, 31, empty, and "two"
  • Every value from 1 to 30, plus 0 and 31

You got correct