Skip to main content
Beginner reading +15 XP

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.

Exercise Multiple Choice

An age field accepts values 18-65. Using equivalence partitioning, what is the MINIMUM number of test values needed?

Exercise Flashcard

What is an equivalence partition (equivalence class)?

Click to reveal answer

Exercise Multiple Choice

You're testing a file upload that accepts .jpg, .png, and .gif files. Which set of partitions is most complete?