- Introduced by
- Glenford Myers
- Year
- 1979
- Type
- partitioning strategy
- Family
- Test case design
What does it do?
Equivalence partitioning divides an input domain into equivalence classes, sets of inputs that are expected to produce the same program behaviour, and selects test cases from each class.
Myers (1979) introduced the technique together with boundary value analysis (BVA), which adds test values at the edges of each class, where off-by-one errors commonly occur.
The intuition behind the method
Exhaustive testing is rarely feasible for a range of integers or a set of text inputs. The method rests on the assumption that if the program handles one value in a class correctly, it will handle the other values in that class correctly too. That assumption is most in doubt at the edges of a class, so boundary values are tested explicitly. Boundary value analysis also assumes a single-fault condition: one input takes an unusual value while the others take nominal values, so each input's classes and edges are examined separately. The result is a small suite that covers every class and its edges.
History
Myers (1979) introduced equivalence partitioning and boundary value analysis in The Art of Software Testing. Beizer (1990) is a further standard reference on software test design, in Software Testing Techniques (2nd ed.).
When to use it
Choose equivalence partitioning when the input domain can be divided into ranges or discrete sets whose members should be treated alike, such as numeric ranges, input validation rules, or parameters of mathematical functions and protocol parsers. Add boundary value analysis when behaviour changes at identifiable thresholds. For floating-point inputs, the method can still be applied, but the assumption that values within a class behave identically should be checked rather than taken for granted, because floating-point comparison and rounding can differ between nearby values. Avoid relying on it as the main technique for complex logical conditions among several inputs; decision table analysis is better suited there, since partitioning inputs one at a time does not capture their combinations.
Limitations and considerations
- Results depend on identifying the right classes; a partition that merges inputs which actually behave differently leaves defects untested.
- Each input is treated as a separate variable. Interactions between inputs, such as two fields that are only invalid in combination, are not covered by selecting values one input at a time.
- The method does not address logic errors inside a class, state-dependent behaviour, or concurrency issues, because these may not vary with the input value that defines the class.
- Boundary selection rests on judgement about where behaviour changes; the guidelines narrow this choice but do not remove it.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Replaces the full input domain with one representative per class, which makes systematic testing of ranges practical.
- Classes are drawn from the specification and input rules, so they tend to reflect the behaviour the designers intended.
- Boundary value analysis targets off-by-one and fence-post errors, which a single representative per class would not reliably catch.
- The procedure is simple to explain, so a team can learn it and review test suites against it.
Applications
- Testing a date validation function by partitioning inputs into valid dates, invalid dates, and boundary dates (such as Feb 28 and Feb 29), together with leap year logic and month boundaries.
- Verifying range checks in API endpoints by identifying the valid parameter range, testing edge values (such as 0, negative values, and the maximum integer), and invalid extremes.
- Testing a discount calculation in e-commerce by partitioning discount tiers, testing order values at the tier thresholds (for example, an order of $50 that triggers a 10% discount), and including edge cases such as zero or negative amounts.
- Validating a login form by partitioning the username and password domains into valid combinations, empty inputs, special characters, length boundaries, and injection-style inputs.
How it works
How it works
Specify the valid input domain from the requirements and divide it into valid classes (inputs the system should accept) and invalid classes (inputs it should reject). Mark the boundary values at the edges of each class, since these are the points where the expected behaviour is most likely to change. Worked example: for an integer input that is valid over the range 0 to 150, the valid class is 0 to 150, the invalid classes are the values below 0 and above 150, and the boundary edges are 0 and 150.
From each class, choose one representative test case. For each boundary, add cases just below, at, and just above the edge, which targets off-by-one and fence-post errors. For the 0 to 150 range, the boundary cases are -1, 0 and 1 at the lower edge and 149, 150 and 151 at the upper edge. Add one interior value of the valid class and one value from each invalid class.
Run the selected cases and compare actual outputs with expected outputs. A failure may reveal a defect in the program or a wrong partition; if the partition was wrong, revise the class definitions and repeat the selection step.
Common pitfalls
- Assuming all inputs in a class behave identically. This assumption is weakest for floating-point arithmetic, where nearby values may round or compare differently.
- Testing only valid classes. Invalid classes and values outside the valid range are needed to check that the program rejects bad input.
- Ignoring state. If the output depends on earlier actions or on configuration, the input value alone does not determine behaviour, and classes drawn from the inputs are incomplete.
- Partitioning only the visible parameters. Hidden inputs such as system configuration or the current time can create additional classes that the specification does not list.
Frequently asked questions
How do I identify equivalence classes for complex inputs?
Start with the domain specification: what values are valid, what ranges exist, and what values are excluded? Group values where program behaviour is expected to be identical. For numeric inputs, typical classes include negative numbers, zero, positive numbers, large values, and values that could cause overflow. For strings, typical classes include empty strings, normal lengths, maximum length, special characters, and non-ASCII characters. Consult the requirements to find partitions based on intended behaviour.
What is the difference between valid and invalid equivalence classes?
Valid equivalence classes contain inputs that meet the system requirements; invalid classes contain inputs that violate them. Test both: valid classes verify correct behaviour, and invalid classes verify error handling. For example, for an age input validated over the range 0 to 150, the valid class is [0, 150] and the invalid classes are values below 0 and values above 150. Include cases from both to check acceptance and rejection logic.
How many test cases should I generate per equivalence class?
There is no fixed count. Each class needs at least one test case, and each boundary adds a few more cases just below, at, and just above the edge. The right number depends on the risk in the function and the number of classes. Adding many more tests within a class that is expected to behave identically adds little information, so the suite should grow with the number of distinct behaviours rather than the number of possible values.
Can equivalence partitioning guarantee I will catch all bugs?
No. Equivalence partitioning is well suited to input validation and range checking. It does not reliably catch logic errors, state-dependent bugs, or concurrency issues. Combine it with other techniques: boundary value analysis (covered here), decision table analysis for complex logic, state-based testing for stateful systems, and exploratory testing for scenarios the specification does not anticipate.
Related methods
Sources
Myers, G. J. (1979). The Art of Software Testing. John Wiley & Sons.
Open publication referenceBeizer, B. (1990). Software Testing Techniques (2nd ed.). International Thomson Computer Press.
Open publication referenceCoppit, D., & Leavens, G. T. (2003). Practical implications of simpler, more scalable path-sensitive data flow analyses. ACM Transactions on Software Engineering and Methodology, 12(3), 261–306.
Open publication reference