Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 60 ยท Test Design Techniques

Boundary Value Analysis

Learn boundary value analysis (BVA): find the edges of ranges, apply two-value and three-value BVA, catch off-by-one bugs, and apply it to money, text lengths and sets.

Programmers make mistakes in a very predictable place: the edges. Should it be age > 18 or age >= 18? Does a password of exactly 8 characters pass or fail? Is a basket worth exactly 50.00 eligible for free delivery? These are off-by-one questions, and developers get them wrong often, because the difference between < and <= is a single character that looks harmless.

Boundary value analysis (BVA) is the test design technique built on that observation. Instead of choosing a value from the middle of each partition, you choose the values at and next to its edges. It is the natural partner of Equivalence Partitioning: partitioning tells you which groups exist, and BVA tells you which values in those groups are most likely to expose a defect.

Real versus stand-in. BVA is a method you apply to real requirements and real systems. The TryIt blocks use a generator and a small function with a deliberately planted bug as stand-ins for a real feature, so you can see the technique catch a defect that ordinary tests miss.

Boundaries of a range

A boundary is the value where one partition ends and the next begins. Suppose a membership form says: "Applicants must be 18 to 65 years old, inclusive." The partitions are:

Partition Values Valid?
Too young 17 and below invalid
Eligible 18 to 65 valid
Too old 66 and above invalid

There are two boundaries: between 17 and 18, and between 65 and 66. Each boundary has a value on each side, so there are four values at the edges: 17, 18, 65 and 66.

Where defects like to hide

Off-by-one < written where <= was meant.
Wrong limit Code uses 17 or 19, not 18.
Rounding Cents and decimals cross the limit.

Edges have more defects than the middle of a range.

1 / 2

Two-value BVA

For each boundary, test the boundary value itself and the closest value in the neighboring partition. For the range 18 to 65:

  • Lower boundary: 17 (invalid) and 18 (valid).
  • Upper boundary: 65 (valid) and 66 (invalid).

That is four tests.

Three-value BVA

For each boundary, test the value just before it, the value on it, and the value just after it. For 18 to 65:

  • Around the lower boundary: 17, 18, 19.
  • Around the upper boundary: 64, 65, 66.

That is six tests. The extra values (19 and 64) catch cases where an implementation treats the first valid value specially or breaks one step inside the range. Choose two-value for low-risk fields and three-value when failures are costly.

What counts as "the next value"

The size of the step depends on the data:

  • Integers: the step is 1, so the neighbors of 18 are 17 and 19.
  • Money: the smallest unit is 0.01, so around a 50.00 free-delivery threshold test 49.99, 50.00 and 50.01.
  • Decimals with other precision: use the smallest step the system accepts or displays.
  • Text length: measure in characters. For a password of 8 to 64 characters, test lengths 7, 8, 9, 63, 64 and 65.
  • Dates and times: the step is a day or a second, depending on what the field stores. A promotion ending at midnight needs values just before and just after midnight.

Always read the requirement closely for inclusive versus exclusive wording. "Under 18" excludes 18; "18 and under" includes it. A vague phrase like "up to 65" is a problem to resolve before testing, as covered in Reviewing Requirements for Testability.

A boundary generator

The first stand-in builds boundary values for a numeric range. It works for any step size, so it can generate money values such as 49.99 and 50.01 as well as whole numbers. The output lists the two-value set and the three-value set side by side.

JS Generating boundary values

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice that the price range produces 0 as its lowest invalid value. If the requirement says "must be greater than zero", then 0 is the interesting boundary value, because a developer might have written price >= 0 by mistake.

Catching a planted off-by-one

Here is the technique in action. The membership function below has a defect: the lower limit uses > instead of >=, so an 18-year-old is rejected. A single mid-range test per partition, as in basic equivalence partitioning, passes every time and misses the defect. The boundary tests expose it.

JS Boundary tests catch what mid-range tests miss

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The mid-range suite reports no failures, while both boundary suites catch the defect at age 18. Change the > in the function to >= and run again to see every suite pass. Then try changing <= 65 to < 65: the boundary suites catch that bug at age 65 too, and the mid-range suite still passes.

Beyond simple ranges

Sets and lists

A set of discrete values, such as the allowed file types or the country list, has no numeric edge. The equivalents of boundaries are:

  • The first and last items.
  • An empty selection, and a selection of exactly one item.
  • The maximum number of items allowed, and one more than the maximum.

Multiple fields

Apply BVA to each field separately. For a form with two ranges, vary one field at its boundaries while holding the other at a valid mid-range value. Combining boundaries of different fields in the same test often hides which value caused a problem.

Output boundaries

Boundaries can also appear in outputs. A bank may stop interest at a cap, or a coupon may never reduce a total below zero. Work backwards: find input values that produce a result at the edge of an output limit.

Hidden boundaries

Look for limits the requirements do not mention, such as the largest number of characters a database column accepts, a maximum upload size, or the largest value of a number type. These are discovered by asking developers or by experimenting, and they are good candidates for the nasty inputs covered in Experience-Based Testing.

BVA and equivalence partitioning together

A typical workflow for a field:

  1. List the partitions (valid and invalid).
  2. Choose boundary values for every partition that has an edge.
  3. Add one representative for partitions without edges, such as "not a number" or "empty".
  4. Write the expected result for each test before running anything.

You can see both techniques working together in Project: Test a Login Form.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. A field accepts values from 1 to 100 inclusive. Which set is the two-value BVA set?

    Two-value BVA takes each boundary and its closest neighbor in the adjacent partition: 0 and 1 around the lower edge, 100 and 101 around the upper edge.
  2. 2. How many tests does three-value BVA need for a single range with two boundaries?

    Each boundary gets three values (before, on, after), so two boundaries give six tests.
  3. 3. A free-delivery rule applies to totals of 50.00 or more, in cents. Which values best test the threshold?

    The smallest money step is 0.01, so the neighbors of 50.00 are 49.99 and 50.01. Those are the values that expose a wrong comparison.
  4. 4. A tester checks ages 10, 40 and 80 for the rule 18 to 65 and all pass, yet the code uses age > 18. What does this show?

    None of those ages sit on a boundary. Only a test with age 18 would fail, so mid-range values miss this defect.
  5. 5. Which is the best boundary pair for a password length rule of 8 to 64 characters?

    Each boundary needs a value on each side: 7 (invalid) and 8 (valid), 64 (valid) and 65 (invalid).

Summary

  • Boundary value analysis tests the edges of partitions, where off-by-one defects concentrate.
  • Two-value BVA tests each boundary and its neighbor across the edge; three-value BVA adds the neighbor on the other side.
  • The size of "one step" depends on the data: 1 for integers, 0.01 for money, one character for text length.
  • Tests with one mid-range value per partition can miss edge defects entirely.
  • For sets, test the first, last, empty and maximum cases, and always combine BVA with equivalence partitioning.

Next: Decision Table Testing.