5.3 Boundary Value Analysis & Positive/Negative Tests
Theory: Boundary Value Analysis & Positive/Negative Tests
Equivalence partitioning (5.2) gives you the partitions. But it raises a new question: which sample should you pick from each partition? The sample carries a big responsibility, because it speaks for the whole group. The answer is boundary value analysis (BVA): most bugs live at the edges of a partition, not in its middle.
Why Bugs Hide at the Edges
Think about a cinema. Children aged 12 and under get a cheap ticket. The programmer writes:
if (age < 12) { price = childPrice; // bug! should be age <= 12} else { price = adultPrice;}
Ages 5, 8 and 10 all get the right price. A random test from the middle of the child partition passes every time. Only a child who is exactly 12 gets the wrong price. A test on the edge finds the bug immediately.
That is the whole reason for BVA. Programmers write the borders of partitions as comparisons (<, <=, >, >=), and the classic slip is choosing the wrong one, or being off by one. Nobody ever looks at the edges, except BVA testers.
The BVA Rule
For every boundary, test three values: exactly on the boundary, just below it, and just above it. If the input is a range from a to b, that means a and b plus the values just around them. If the input is a number of values (a count), test the minimum and maximum too.
Example: an exam mark from 0 to 75
The valid range is 0≤mark≤75. It has two boundaries, so BVA gives six tests: −1, 0, 1 around the lower edge and 74, 75, 76 around the upper edge.
BVA for an exam mark from 0 to 75: test −1, 0, 1 and 74, 75, 76. Bugs love to sit on the edges.
Notice that each edge produces one value from each side: −1 is in the invalid partition below, 0 and 1 are valid; 74 and 75 are valid, 76 is invalid. So the BVA values also exercise the invalid partitions from EP.
EP and BVA Work as a Team
Step
Technique
What you do
1
EP first
Find all the partitions: valid and invalid, inputs and outputs.
2
BVA next
For each partition, pick the samples on and around its boundaries.
3
Test
If a sample passes, the partition passes. If it fails, the partition fails.
Exam radar: EP and BVA have different purposes but work hand in hand. EP finds the partitions; BVA picks effective samples from them. BVA answers the question: how do we know our samples are good?
Positive and Negative Tests
Every test design should include both kinds of test. You met them in Lecture 2 with the calculator.
Think of a shop. A positive test is a polite customer: they ask for something on the menu, pay the right amount and wait their turn. A negative test is a clumsy or naughty customer: they order something that does not exist, pay with a button, or leave the form half-filled. Real software meets both kinds of customer, so it must be tested with both.
Positive test
Negative test
Goal
Check that the software works under normal conditions.
Check that the software handles bad or unexpected input safely.
Input
Valid data. Normal use.
Invalid, out of range, wrong type, missing data.
Expected result
The correct output.
An error message or a clean rejection. No crash.
Grade example (5.4)
exam 44, coursework 15 → B
exam 80 → fault message; exam 'Q' → fault message
A negative test still has an expected result: “the program shows a fault message and keeps running” is a precise expectation. “Something goes wrong” is not.
Common mistake: testing only the polite customer. A test set made only of valid inputs never checks whether the program survives the clumsy one, and in production the clumsy customer always arrives.
Worked Examples
Exercise 1
Which values does BVA test for a range from 1 to 100?
Show solution ↓Hide solution ↑
Solution
The range has two boundaries, 1 and 100. For each, test on, just below and just above:
lower edge: 0, 1, 2,
upper edge: 99, 100, 101.
Six values: 0 and 101 are invalid (negative tests), 1, 2, 99 and 100 are valid.
Exercise 2
Why do we need BVA if we already have EP?
Show solution ↓Hide solution ↑
Solution
EP tells us the partitions, but not which sample to pick from each one. Since every member of a partition is assumed to behave the same, a sample from the middle looks as good as any other. But most bugs sit at the boundaries (a < that should have been <=, an off-by-one), and a middle value never touches them.
BVA picks samples on and around the edges, so the one sample that speaks for each partition is also the one most likely to reveal a bug. EP finds the groups; BVA makes the samples effective.
Exercise 3
A cinema gives a child price to ages 12 and under. The code says if (age < 12). Which of the test ages 5, 10, 12 and 13 reveals the bug? Which BVA tests would you choose for this boundary?
Show solution ↓Hide solution ↑
Solution
Compare the specification (child if age ≤12) with the code (child if age <12):
Age
Spec says
Code gives
Bug revealed?
5
child
child
no
10
child
child
no
12
child
adult
yes
13
adult
adult
no
Only age 12 reveals the bug. BVA chooses the values on and around the boundary, 11, 12 and 13, so it is guaranteed to include 12. Random middle values like 5 and 10 never find it.
Exercise 4
An age field accepts 18 to 60. Give the EP partitions, then the BVA test values, and label each value as a positive or negative test.
Show solution ↓Hide solution ↑
Solution
EP: a range, so 1 valid + 2 invalid partitions: below 18 (invalid), 18 to 60 (valid), above 60 (invalid).
BVA: two boundaries, three values each.
Value
Partition
Kind of test
Expected result
17
below 18
negative
rejected with an error message
18
valid
positive
accepted
19
valid
positive
accepted
59
valid
positive
accepted
60
valid
positive
accepted
61
above 60
negative
rejected with an error message
Six tests: 17, 18, 19, 59, 60, 61, of which 17 and 61 are negative tests.
Exercise 5
In the grade example (exam mark out of 75, coursework out of 25), give one positive and one negative test.
Show solution ↓Hide solution ↑
Solution
Positive: exam 44, coursework 15 → total 59 → expected B. Both inputs are valid and the program should behave normally.
Negative: exam 80, coursework 10 → expected fault message (the exam mark is above 75). The program must reject the input cleanly, without crashing.
Exercise 6
A colleague says: “A negative test has no expected output, because the input is wrong anyway.” Is that right?
Show solution ↓Hide solution ↑
Solution
No. Every test case needs an expected result, or you cannot decide whether it passed. For a negative test the expected result is the safe handling the specification requires: a specific error or fault message, or a clean rejection, and no crash. For example, exam mark 'Q' → expected “fault message”, program keeps running. If the program crashed, or quietly computed a grade, the negative test fails and has found a bug.