Equivalence Partitioning
You're testing an age field that accepts values from 18 to 65. Do you need to test every number? 18, 19, 20, 21... all the way to 65? That's 48 tests for one field. Multiply that by every field in your application, and you'll be testing until retirement.
Equivalence partitioning is the technique that saves you from that nightmare.
The Idea
The insight is simple: if the system treats all values in a range the same way, testing one value from that range is enough. You partition the inputs into groups (classes) where the software behaves equivalently, then test one representative from each group.
For our age field (valid range: 18-65), the partitions are:
| Partition | Example Value | Expected Behavior |
|---|---|---|
| Below minimum (< 18) | 15 | Rejected — error message |
| Valid range (18-65) | 30 | Accepted |
| Above maximum (> 65) | 70 | Rejected — error message |
Three tests instead of 48. And they cover all the meaningful scenarios.
Why It Works
If the code correctly handles age 30, it will almost certainly handle 31, 32, and 45 the same way. They're all in the same equivalence class — the code path is identical. Testing all of them adds effort without adding information.
But ages 15 and 70 exercise different code paths — the validation logic, the error handling. Those are where bugs hide.
Applying It to Real Scenarios
Email field: Three partitions — valid format (user@example.com), invalid format (missing @, no domain), and empty string.
Quantity in a shopping cart: Three partitions — zero (edge case), valid range (1-99), above maximum (100+).
File upload: Valid file types (.jpg, .png), invalid types (.exe, .bat), and no file selected.
The Trap
Don't assume you always have exactly three partitions. A shipping calculator with zones (domestic, continental, international, restricted countries) has four valid partitions plus invalid ones. Think about how the system groups inputs, not just "valid/invalid."
Exercise
A password field requires: 8-20 characters, at least one uppercase letter, at least one number. Identify all the equivalence partitions. How many test cases do you need at minimum?
The key takeaway: One test per partition. Test smart, not exhaustive.
An age field accepts values 18-65. Using equivalence partitioning, what is the MINIMUM number of test values needed?
Equivalence partitioning divides inputs into classes where the system behaves the same. Here there are 3 partitions: below minimum (<18), valid range (18-65), and above maximum (>65). One representative value from each partition is sufficient.
What is an equivalence partition (equivalence class)?
Click to reveal answer
A group of input values that the system treats the same way — they follow the same code path and produce the same type of result. Testing one representative value from the partition is sufficient because all values in the group behave equivalently.
Click to flip back
You're testing a file upload that accepts .jpg, .png, and .gif files. Which set of partitions is most complete?
The most complete partitioning includes valid file types, invalid file types, and the empty/no-selection case. While you only need one representative from each partition, recognizing that "no file" is a separate partition from "invalid file type" is key.