Boundary Value Analysis
Boundary value analysis sounds boring until it catches a bug that would have cost your company real money. Here's how it works, and why bugs love to hang out at the edges.
Where Bugs Live
Think about the age field from the last lesson (valid range: 18-65). Equivalence partitioning told us to test one value from each group. But which value?
Experience shows that bugs cluster at boundaries — the edges where one behavior switches to another. Off-by-one errors are among the most common bugs in software. A developer writes if (age > 18) when they meant if (age >= 18), and suddenly 18-year-olds can't register.
The Technique
For every boundary, test:
- The value just below the boundary
- The boundary itself
- The value just above the boundary
For our age field (18-65):
| Test Value | Why |
|---|---|
| 17 | Just below the lower boundary |
| 18 | The lower boundary itself |
| 19 | Just above the lower boundary |
| 64 | Just below the upper boundary |
| 65 | The upper boundary itself |
| 66 | Just above the upper boundary |
Six tests that are far more likely to find bugs than testing random values like 30, 40, 50.
Combining with Equivalence Partitioning
These two techniques work together. Equivalence partitioning tells you which groups to test. Boundary value analysis tells you which values within those groups are most likely to reveal bugs.
Together, they give you maximum coverage with minimum effort.
Real-World Examples
Shopping cart quantity (1-99): Test 0, 1, 2, 98, 99, 100. The boundaries at 0→1 and 99→100 are where the discount logic, shipping calculation, or stock validation is most likely to break.
Date fields: February 28th vs 29th (leap year), December 31st vs January 1st, month boundaries. Date arithmetic is notoriously buggy.
String length (max 255 characters): Test 254, 255, and 256. Database column overflows are a classic boundary bug.
Exercise
A flight booking system offers these fare classes based on how many days before departure you book:
- 0-7 days: Premium fare ($500)
- 8-21 days: Standard fare ($300)
- 22+ days: Early bird fare ($200)
List all the boundary values you'd test and the expected fare for each.
The key takeaway: Bugs love boundaries. Test the edges first, the middle later.
A shopping cart allows quantities from 1 to 99. Which set of boundary values should you test?
Boundary value analysis tests just below, at, and just above each boundary. For the range 1-99, the lower boundary values are 0, 1, 2 and the upper boundary values are 98, 99, 100. This catches off-by-one errors at both edges.
Why do bugs cluster at boundary values?
Click to reveal answer
Off-by-one errors are among the most common bugs in software. Developers often confuse > with >=, or < with <=, causing incorrect behavior exactly at the edge where one behavior switches to another.
Click to flip back
A flight booking system charges Early Bird fare for bookings made 22+ days before departure. Which boundary values would test the transition between Standard and Early Bird fares?
The boundary between Standard fare (8-21 days) and Early Bird fare (22+ days) is at day 22. Testing 21 (just below), 22 (the boundary), and 23 (just above) checks for off-by-one errors at this specific transition.