Friday, June 26, 2009

Equivalence Partitioning


Definition of Equivalence Partitioning

Equivalence Partitioning is a black-box testing technique (basic test-design technique) that splits the input domain into classes of data. From this data we can derive test cases.

Test-case design with the help of equivalence partitioning technique has two steps:

1) Identifying the equivalence classes.
2) Defining the test cases.

Example 1 of Equivalence Partitioning

Problem:

The program reads three integer values from an input dialog. The three values represent the lengths of the sides of a triangle. The program displays a message that states whether the triangle is scalene, isosceles, or equilateral. Remember that a scalene triangle is one where no two sides are equal, whereas an isosceles triangle has two equal sides, and an equilateral triangle has three sides of equal length. Moreover, the angles opposite the equal sides in an isosceles triangle also are equal (it also follows that the sides opposite equal angles in a triangle are equal), and all angles in an equilateral triangle are equal.
(Source: http://www.amazon.com/Art-Software-Testing-Glenford-Myers/dp/0471043281)

Solution:

As seen in the definition above we have to identify equivalence classes and define test cases based on those classes.

Equivalence Classes for the triangle problem




Test Cases (Valid) for Equilateral Triangle

Test Case #Side1Side2
Side3Expected Output
1555Equilateral


Test Cases (Valid) for Isosceles Triangle

Test Case #Side1Side2
Side3Expected Output
1223Isosceles
2232Isosceles
3322Isosceles


Test Cases (Valid) for Scalene Triangle

Test Case #Side1Side2
Side3Expected Output
1346Scalene
2364Scalene
3436Scalene


Test Cases (Invalid) Not a Triangle

Test Case #Side1Side2
Side3Expected Output
1
3
1
2
Not a triangle
2
2
3
1
Not a triangle
3
1
2
4
Not a triangle


More solutions to the triangle problem

Solution 1

Solution 2

Solution 3

Solution 4

Software Engineering. By K K Aggarwal, Yogesh Singh

Pragmatic software testing By Rex Black also has solution

Example 2 of Equivalence Partitioning

The specifications for a application software system for authenticating expenses claim for motel accomodation for one night includes the following requirements:

Upper limit is $100 for accomodation expenses claims.
Any claims above $100 should be rejected and should cause an error message to be displayed.
Expense amounts should be greater than $0 and an error message should be displayed otherwise.



Designing test cases

Test case IDMotel ChargeEquivalence classExpected output
1650 < Motel Charge<=100 OK
2-24Motel Charge <=0Error message
3110Motel Charge > 100Error message



Another Example of Equivalence Partition

Another Good Example on Equivalence Partitioning


Advantages of Equivalence Partitioning

It decreases the scope of extensive testing to a well-defined set of test procedures i.e. it reduces the number of required test cases by identifying classes of data. This in a way also helps to reduce redundant test cases.

Drawbacks of Equivalence Partitioning

The resultant test procedures do not include other types of tests that may have a high likelihood of finding an error. e.g. suppose for some problem we might need to define equivalence classes for infinite number of days.

first day of month

middle day of month

last day of month

last day of year

28th of February, non-leap year

28th of February, leap year

29th of February, leap year

In this way we surely bring down the number of test cases but equivalence partitioning may not check unexpected input as 32nd of November.


Equivalence Partitioning - Multiple Choice Questions


Also See - More to read on Equivalence Partitioning:

1. shrinik.blogspot.com
2. Test Education
3. csee.usf.edu
4. Test Education
5. Glasnost
6. it.toolbox.com
7. After the Y2K fireworks By Bhuvan Unhelkar
8. Turning Equivalence Class Partitioning Into Child’s Play, an article in stpmag
9. Another worth reading article by Michael Bolton on Domain & Equivalence Partitioning

Related Post:
Boundary Value Analysis