Boundary values
In short: A boundary is the last value of one partition and the first of the next. With two points you test the boundary and its neighbour from the other partition: 49.99 and 50.00 €. With three points, the neighbours on both sides too: 49.99, 50.00 and 50.01 €. That catches ">" instead of ">=", rounding and off-by-one bugs, which a representative from the middle of the partition never sees.
Problem
The tests passed, the boundary did not
From the previous lesson you have three delivery tests: 0 €, 30 € and 80 €. They all pass. The developer wrote:
delivery is free if the total is > 50
A cart of 50.00 € pays 4.90 €. The test with 80 € is from the same partition and passes, because 80 is both > 50 and >= 50. A representative from the middle of the partition cannot see where exactly the partition ends.
The idea
The boundary
The delivery partitions are ordered: empty, paid, free. Where one partition ends and the next begins is the boundary:
| Partition | From | To |
|---|---|---|
| empty cart | 0 € | 0 € |
| paid delivery | 0.01 € | 49.99 € |
| free delivery | 50.00 € | no upper boundary |
The boundary values are the smallest and largest value of each partition. Bugs are densest here, because this is where the developer decides ">" or ">=", rounds, counts from 0 or from 1. One wrong stroke in the code moves the boundary by one step. The step for amounts is one cent.
Boundary value analysis only works for ordered partitions: amounts, counts, dates. A payment method has no "before" and "after".
The idea
Two points and three points
There are two ways.
With two points: for every boundary you test the boundary value and its neighbour from the other partition. For delivery: 0 and 0.01 €; 49.99 and 50.00 €. Four tests.
With three points: for every boundary value you test it and both its neighbours. Around 50.00 €: 49.99, 50.00 and 50.01 €.
Why three? Imagine code saying "delivery is free if the total is exactly 50". With two points: 49.99 pays, 50.00 is free. It passes. With three points, 50.01 € has to be free, and the code charges 4.90 €. Caught.
Three points cost more tests and catch more bugs. Which one to choose depends on the risk: for payment they are worth it, for the colour of a button they are not.
More precisely, if you are curious
ISTQB CTFL v4.0.1 describes the technique in section 4.2.2 (boundary value analysis) with both variants: 2-value BVA and 3-value BVA. Coverage is the number of tested boundary values (with their neighbours for three points) over all of them. According to the syllabus three points are more rigorous: they catch bugs that two points miss.
The technique builds on equivalence partitions. Without partitions it is not clear where the boundaries are, and without boundaries partitions miss the most common bugs.
Try it
Which values?
The idea
49.99 is not 30
49.99 € and 30 € are in one partition. So why is 49.99 the better test?
Because some bugs only show next to the boundary. If the code rounds the total to whole euros before comparing, 49.99 € becomes 50 € and delivery becomes free. 30 € rounded is still 30, and the test passes.
A good test sits where the bug would show itself. The middle of the partition is the safest place, and that is why it is the worst place for a test.
Try it
The boundaries of delivery
Write the tests for the boundaries of delivery, with two points. Catch all the bugs with as few rows as you can.
The rule: Delivery is free for an order from 50 € inclusive, otherwise it is 4.90 €. An empty cart cannot be ordered.
| Input | Expected | The correct system | |||
|---|---|---|---|---|---|
| # | Cart total | Refused | Delivery | ||
An empty result cell is not checked. Amounts are written like 49.99.
Solution
| Cart total | Refused | Delivery |
|---|---|---|
| 0 | yes | |
| 0.01 | no | 4.90 |
| 49.99 | no | 4.90 |
| 50 | no | 0 |
Four rows: 0 € (refused), 0.01 € (4.90 €), 49.99 € (4.90 €), 50.00 € (0.00 €). 50.00 € catches ">" instead of ">=". 49.99 € catches the rounding and the threshold written as 5 € instead of 50 €. If you put 30 € instead of 49.99 €, the rounding slips through. If you put 80 € instead of 50.00 €, ">" slips through.
The idea
Boundaries are everywhere
Wherever a rule has a number, it has a boundary:
- Counts: at most 10 of a product. 10 is accepted, 11 is refused. And from below: you add at least 1 item, so 0 is refused.
- Days: returns within 14 days of receipt. Received on 1 October: 15 October is accepted, 16 October is refused.
- Time: the code is valid until 31 October. 23:59, and 00:00 on 1 November. And by whose clock?
- Two boundaries at once: the limit is on the items in the cart, not on what is added. 9 in the cart plus 1 is 10 and is accepted. 10 plus 1 is 11 and is refused.
A boundary value often opens a question the requirement did not ask. "Within 14 days": inclusive? From receipt or from delivery? That is reviewing too: test design done early is the best checklist for requirements.
Exercise
The boundaries of the limit and of the days
1. The cart limit. There are two boundaries: on the quantity added and on the items in the cart after adding.
Write the tests for the two boundaries of the limit: how many are added (0 and 1) and how many end up in the cart (10 and 11). Check what stays in the cart too.
The rule: The cart can hold at most 10 of one product. Adding beyond 10 is refused with a message, and the cart stays the same. You add at least 1 item.
| Input | Expected | The correct system | ||||
|---|---|---|---|---|---|---|
| # | In the cart | Adding | Refused | In the cart after | ||
An empty result cell is not checked. Amounts are written like 49.99.
Solution
| In the cart | Adding | Refused | In the cart after |
|---|---|---|---|
| 5 | 0 | yes | 5 |
| 5 | 1 | no | 6 |
| 9 | 1 | no | 10 |
| 10 | 1 | yes | 10 |
Four rows: (5, add 0) is refused; (5, add 1) becomes 6; (9, add 1) becomes 10; (10, add 1) is refused and 10 stay. The row (9, 1) catches the code that refuses the 10th item. The row (10, 1) catches the code that lets the 11th in, the one that compares only what is added, and the one that empties the cart on a refusal. If all rows start with an empty cart, the last two slip through.
2. Days and counts. Find the boundary values.
Test
Check yourself
Related lessons
Section titled "Related lessons"- Builds on: Why programs fail · The good requirement · Acceptance criteria · Equivalence partitions
- Continues in: Decision tables · State transitions · Code coverage · Testing from experience
- Tasks on this topic: Test design techniques