Ch. 22 · Software Testing

Boundary-Value Tests and Off-By-One Errors

Boundary-Value Tests and Off-By-One Errors. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readbeginnerupdated Oct 3, 2026

Boundary testing exercises transitions between valid and invalid input. Values immediately below, at and above a boundary often expose incorrect comparisons.

Before you start

You should understand inputs, expected outputs and the boundaries of the component under test. State the risk a test should detect before choosing a tool or mock. Distinguish controlled dependencies from real integrations so the result does not imply more coverage than the test actually provides.

The practical goal is to reason through this situation: For a limit of ten items, test nine, ten and eleven. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.

Step-by-step walkthrough

Step 1: Locate the transition

Write whether the limit is inclusive or exclusive.

Step 2: Test adjacent values

Use immediately below, exactly at and above the boundary.

Step 3: Control time if needed

Expiry logic must read the same clock the test controls.

Worked scenario

For a limit of ten items, test nine, ten and eleven.

If a token expires at time 100 and validity requires now less than 100, it is valid at 99 and invalid at 100 and 101. A test only at 50 cannot distinguish less-than from less-than-or-equal. Precision and units also matter when production timestamps use milliseconds or another resolution.

Common mistake

Testing only ordinary middle values misses inclusive-versus-exclusive mistakes.

Verify the behavior

Check both sides and equality under the documented units and comparison rule.

Interview exercise

Test a time expiry.

Answer and reasoning

Control the clock and check just before, exactly at and after the defined expiration rule.

Continue learning

Compare the scenario with the Software Testing interview questions and test your understanding with the Software Testing MCQs. For terminology and implementation details, consult the reference material.

More in Software Testing

read ✓Software Testing · hard

Testing Time with an Injected Clock

Inject a clock instead of calling the system time, freeze it in tests, and remove the sleeps that make tests flaky.

~2 min readread →
read ✓Software Testing · mid

Code Coverage and Its Limits

Read line and branch coverage as a signal, not a goal, and avoid the tests that chase the number without checking behavior.

~2 min readread →
read ✓Software Testing · hard

Scoping End-to-End Tests

Reserve end-to-end tests for critical user journeys, use stable selectors, and avoid duplicating coverage the lower tests already have.

~2 min readread →
esc