Equivalence partitioning is a black-box software testing technique that divides input data into classes (partitions) where each class is expected to be treated the same by the system. You choose test cases by picking one representative value from each partition, which reduces the number of tests while maintaining good coverage. This article explains the method, how to apply it, and common pitfalls.
Formula
The core idea is to partition the input domain into equivalence classes. For a range of valid inputs from min to max, there are three standard partitions:
- Valid partition: values between min and max inclusive.
- Invalid partition (below): values less than min.
- Invalid partition (above): values greater than max.
Each partition is represented by a single test value. The formula for the number of test cases is simply: Number of partitions = Number of test cases. For a simple range, that is 3 test cases (one from each partition).
Worked Example
Consider a field that accepts a number between 1 and 100 (inclusive). Using the default values from the calculator:
- Valid partition: pick 50 (any value between 1 and 100 works).
- Invalid partition (below): pick 0 (less than 1).
- Invalid partition (above): pick 101 (greater than 100).
These three test cases cover all possible behavior groups. The calculator above checks if a value is within the range; for 50 it returns 1 (valid), for 0 and 101 it returns 0 (invalid).
Why Use Equivalence Partitioning?
Software systems often process a huge number of possible inputs. Testing every single value is impractical. Equivalence partitioning is based on the assumption that if the system works for one value in a partition, it will work for all values in that same partition. This assumption holds for most well-implemented systems, making the technique a cornerstone of efficient test design.
It is especially useful when:
- Input ranges are large (e.g., integers from 1 to 1,000,000).
- Input is a set of valid options (e.g., a list of country codes).
- You need to create a smoke test suite quickly.
How to Choose Test Cases: Step-by-Step
- Identify the input: Determine what data the system accepts (e.g., age, temperature, email address).
- Define partitions: Group inputs into classes that the system should treat identically. For a numeric range, you have one valid and two invalid partitions. For a boolean, you have true and false. For an enumerated list, each option is a partition.
- Pick one representative value per partition: Choose a typical value from each class. For the valid partition, pick a value in the middle; for invalid partitions, pick a value just outside the boundary.
- Add boundary values (optional but recommended): Boundary value analysis is a complementary technique where you test values at the edges of each partition (e.g., min, min-1, max, max+1). This catches off-by-one errors, which are common.
- Consider invalid partitions for every input: Many testers forget to test invalid data. Always include at least one invalid partition per input.
Common Mistakes and Misconceptions
- Picking random values instead of representative ones: The value should be typical of the partition, not an outlier.
- Forgetting invalid partitions: Testing only valid inputs misses a huge class of bugs.
- Assuming one partition per input: A single input can have multiple valid partitions (e.g., a date field has valid months, days, and years).
- Confusing equivalence partitioning with boundary value analysis: They are related but distinct. Equivalence partitioning tests one value per class; boundary value analysis tests the edges of each class.
- Not applying it to output values: You can partition output domains too, ensuring that each type of output is exercised.
Equivalence Partitioning vs. Boundary Value Analysis
These two techniques are often taught together, but they serve different purposes. Equivalence partitioning reduces the number of test cases by selecting one representative per class. Boundary value analysis focuses on the edges of those classes, where bugs are most likely to occur. In practice, you use both: first partition the input space, then test the boundaries of each partition. For a range of 1-100, equivalence partitioning gives you 3 test cases (e.g., 0, 50, 101), while boundary value analysis gives you 4 (1, 100, 0, 101). Combining them yields a robust test suite.
Limitations and When to Use Alternatives
Equivalence partitioning assumes that all values in a partition behave identically. This is not always true, especially when the system has complex internal logic that depends on specific values (e.g., a discount rate that changes at every 10 units). In such cases, you need to create more granular partitions. Also, the technique does not test interactions between inputs. For that, you would use pairwise testing or decision tables. Equivalence partitioning is best used as a first pass to achieve broad coverage quickly, then supplemented with other techniques for thoroughness.
Frequently Asked Questions
What is an equivalence class?
An equivalence class is a set of input values that the system is expected to handle in the same way. For example, for a field that accepts integers from 1 to 100, all values from 1 to 100 form one valid equivalence class. All values less than 1 form an invalid equivalence class, and all values greater than 100 form another.
How many test cases do I need for a simple range?
For a simple range with one valid and two invalid partitions, you need at least three test cases: one valid value, one below the range, and one above the range. If you add boundary value analysis, you would test the exact boundaries as well, bringing the total to five or more.
Can equivalence partitioning be applied to non-numeric inputs?
Yes. For example, a text field that accepts an email address has valid partitions (e.g., a standard email format) and invalid partitions (e.g., missing @, missing domain). Each distinct format that the system treats differently is a separate class.
What is the difference between equivalence partitioning and boundary value analysis?
Equivalence partitioning selects one representative value from each class to reduce the number of tests. Boundary value analysis specifically tests the values at the edges of each class, because that is where errors are most likely. They are often used together.
Does equivalence partitioning guarantee that all bugs are found?
No. It is a risk-based technique that assumes values within a class behave identically. If that assumption fails (e.g., due to hidden logic), bugs can be missed. It should be combined with other testing techniques like boundary value analysis, decision tables, and exploratory testing.
How do I partition a list of valid options?
Each option in the list is a separate equivalence class. For example, if a dropdown has three options (A, B, C), you should test at least one case for each option. Additionally, you should test what happens when no option is selected (an invalid partition).
Related
Formula used
in min | Min valid value | - | 1 | -1000000 | 1000000 in max | Max valid value | - | 100 | -1000000 | 1000000 in val | Value to test | - | 50 | -1000000 | 1000000 out is_valid | Is value in range? | - | (val >= min && val
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More in this bed
- How to Find Leaked Passwords in Chrome, Edge, Wallet & iCloud Keychain
- Fingerprint Limit Reached on MacBook Pro: Fix It
- WhatsApp Call Errors: Meanings & Fixes
- Error 0x8007025d: Fix Windows Install Fails
- Net Framework 3.5 Installation Error 0x800f0950
- How to Organize Google Photos with Face Groups & Labels