Monday, April 5, 2010

Equivalence Partitioning

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



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 <>OK
2-24Motel Charge <=0Error message
3110Motel Charge > 100Error message






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 Example

Grocery Store Example

Consider a software module that is intended to accept the name of a grocery item and a list of the different sizes the item comes in, specified in ounces. The specifications state that the item name is to be alphabetic characters 2 to 15 characters in length. Each size may be a value in the range of 1 to 48, whole numbers only. The sizes are to be entered in ascending order (smaller sizes first). A maximum of five sizes may be entered for each item. The item name is to be entered first, followed by a comma, then followed by a list of sizes. A comma will be used to separate each size. Spaces (blanks) are to be ignored anywhere in the input.

Derived Equivalence Classes

  1. Item name is alphabetic (valid)
  2. Item name is not alphabetic (invalid)
  3. Item name is less than 2 characters in length (invalid)
  4. Item name is 2 to 15 characters in length (valid)
  5. Item name is greater than 15 characters in length (invalid)
  6. Size value is less than 1 (invalid)
  7. Size value is in the range 1 to 48 (valid)
  8. Size value is greater than 48 (invalid)
  9. Size value is a whole number (valid)
  10. Size value is a decimal (invalid)
  11. Size value is numeric (valid)
  12. Size value includes nonnumeric characters (invalid)
  13. Size values entered in ascending order (valid)
  14. Size values entered in nonascending order (invalid)
  15. No size values entered (invalid)
  16. One to five size values entered (valid)
  17. More than five sizes entered (invalid)
  18. Item name is first (valid)
  19. Item name is not first (invalid)
  20. A single comma separates each entry in list (valid)
  21. A comma does not separate two or more entries in the list (invalid)
  22. The entry contains no blanks (???)
  23. The entry contains blanks (????)
Black Box Test Cases for the Grocery Item Example based on the Equivalence Classes Above.
# Test Data Expected Outcome Classes Covered
1 xy,1 T 1,4,7,9,11,13,16,18,20,22
2 AbcDefghijklmno,1,2,3 ,4,48 T 1,4,7,9,11,13,16,18,20,23
3 a2x,1 F 2
4 A,1 F 3
5 abcdefghijklmnop F 5
6 Xy,0 F 6
7 XY,49 F 8
8 Xy,2.5 F 10
9 xy,2,1,3,4,5 F 14
10 Xy F 15
11 XY,1,2,3,4,5,6 F 17
12 1,Xy,2,3,4,5 F 19
13 XY2,3,4,5,6 F 21
14 AB,2#7 F 12


No comments:

Post a Comment