Equivalence Partitioning Tutorial



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 #
Side1
Side2
Side3
Expected Output
1
5
5
5
Equilateral

Test Cases (Valid) for Isosceles Triangle
Test Case #
Side1
Side2
Side3
Expected Output
1
2
2
3
Isosceles
2
2
3
2
Isosceles
3
3
2
2
Isosceles

Test Cases (Valid) for Scalene Triangle
Test Case #
Side1
Side2
Side3
Expected Output
1
3
4
6
Scalene
2
3
6
4
Scalene
3
4
3
6
Scalene

Test Cases (Invalid) Not a Triangle
Test Case #
Side1
Side2
Side3
Expected 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


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 ID
Motel Charge
Equivalence class
Expected output
1
65
0 < Motel Charge<=100
OK
2
-24
Motel Charge <=0
Error message
3
110
Motel Charge > 100
Error message

Another Example of Equivalence Partition



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.


2 comments:

Anonymous said...

nice post. thanks.

rohit said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

kajal hot