Equivalence partitioning (also called Equivalence Class Partitioning or ECP) is a software testing technique that divides the input data of a software unit into partitions of equivalent data from which test cases can be derived.
- Equivalence partitioning (EP) is a specification-based or black-box technique applicable to all level of testing: unit, system, integration etc.
- Equivalence partitioning is a testing technique where input values set into classes for testing. Valid Input Class = Keeps all valid inputs and Invalid Input Class = Keeps all Invalid inputs.
- In principle, test cases are designed to cover each partition at least once.
- An advantage of this approach is reduction in the time required for testing a software due to lesser number of test cases.
- The equivalence partitions are usually derived from the requirements specification for input attributes that influence the processing of the test object.
The equivalence-partitioning technique requires that we need to test only one condition from each partition. If one condition in a partition works, we assume all of the conditions in that partition will work.
The equivalence class is a set of data values that the tester assumes are processed in the same way by the test object. Besides equivalence classes for correct input, those for incorrect input values must be tested as well.
For every input data element that should be tested, the domain of all possible input value is determined. This domain is the equivalence class containing all valid or allowed input value. The values outside of this domain are seen as equivalence classes with invalid input values.
The next step is refining the equivalence classes. For every single equivalence class, a representative value should be chosen for a test case.
To complete the test cases, the tester must define the preconditions and the expected result for every test case. The same principle of dividing into equivalence classes can be used for the output data. Partitioning into equivalence classes and selecting the representatives should be done carefully. The probability of failure detection is highly dependent upon the quality of the partitioning as well as which test case are executed.
The best test values are certainly those verifying the boundaries of equivalence classes. The equivalence class for incorrect values is derived from the following consideration that incorrect values are numbers that are greater or smaller than the range of the applicable interval or every non-numeric value. Zero is also an input, which often leads to failure.
The equivalence class technique results in at least 2 equivalence classes(one valid and one invalid) for each of these parameters of the test object. In order to specify a test case, we must assign each parameter an input value.
The representatives of invalid equivalence classes are not combined. An invalid value should only be combined with valid ones because an incorrect parameter value normally trigger an exception handling.
1. Identifying the domain: Identify the domain for every input parameter. With this technique, at lease one valid and one invalid equivalence class per parameter has been derived exclusively from the interface specification.
2. Refine the equivalence classes based on the specification: In order to further subdivide equivalence classes, information about the functionality of method is needed.
3. Select Representative: To get input data, one representative value must be chosen for every equivalence class. According to equivalence class theory, any value of an equivalence class can be used.
4. Combine the test cases: Combine the values to test cases.
Example-1: Equivalence partitioning for item Discount
Problem: A shopping website offers different discounts depending upon purchase made by the customer. For example if customer purchase is in the range $1 to $50 then there is no discount, a purchase over $50 and up to $200 has 5% discount. Purchase between $201 and up to $500 has 10% discount, and purchase over $501 has 15% discount. Identify valid and invalid equivalence partitioning.
Invalid Partition: $0.01
Valid(No Discount): $1-$50
Valid (5%): $51-$200
Valid (10%): $201-$500
Valid (15%): $501-Above
EC-coverage - (number of tested EC/total number of EC) x 100%
Equivalence class partitioning is a systematic technique. It contributes to a test where specified conditions and restrictions are not overlooked. Equivalence classes can not be determined only for inputs and outputs of methods and functions.