Latticework

Command Palette

Search for a command to run...

Testing

Test Design

16 min

Explanation

Good test DESIGN isn't about writing MORE tests — it's about writing the RIGHT tests, ones likely to actually catch bugs. Boundary value analysis is a systematic technique: bugs cluster disproportionately at the EDGES of valid ranges (off-by-one errors are the classic example), so test exactly at and just outside every boundary, not just "typical" values in the middle.

def boundary_test_values(min_val, max_val):
    return [min_val - 1, min_val, max_val, max_val + 1]

print(boundary_test_values(1, 10))   # [0, 1, 10, 11]
Try it

Testing age=60 (a typical, 'safe' middle value) would never catch an off-by-one bug in the boundary check -- testing age=-1, 0, 120, and 121 specifically targets exactly where an off-by-one error would actually show up.

Loading editor…
Explanation

The insight behind boundary testing: an off-by-one bug (< instead of <=, or a range that's one too wide/narrow) is invisible everywhere EXCEPT right at the boundary. Testing age = 60 would pass regardless of whether the check used < or <= — testing age = 120 and age = 121 specifically is what actually distinguishes correct from off-by-one-wrong:

def is_valid_boundary_case(value, min_val, max_val):
    return min_val <= value <= max_val

This same principle generalizes beyond numeric ranges: empty lists (the "boundary" of collection size), empty strings, the first/last element of a sequence — anywhere a range or size has an edge is exactly where boundary-focused test design pays off most.

Exercise

Write `boundary_test_values(min_val, max_val)`: return the four classic boundary-value-analysis test points for a valid range — `[min_val - 1, min_val, max_val, max_val + 1]`.

Exercise

Write `is_valid_boundary_case(value, min_val, max_val)`: return True if `value` falls within the INCLUSIVE range `[min_val, max_val]`.

Quiz

What is 'boundary value analysis' in test design?

Checkpoint

You can design boundary-value test cases that specifically target off-by-one bugs, rather than only testing "typical" middle-of-the-range inputs.