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 # | 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 |
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 ID | Motel Charge | Equivalence class | Expected output |
---|---|---|---|
1 | 65 | 0 <> | OK |
2 | -24 | Motel Charge <=0 | Error message |
3 | 110 | Motel Charge > 100 | Error 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
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
- Item name is alphabetic (valid)
- Item name is not alphabetic (invalid)
- Item name is less than 2 characters in length (invalid)
- Item name is 2 to 15 characters in length (valid)
- Item name is greater than 15 characters in length (invalid)
- Size value is less than 1 (invalid)
- Size value is in the range 1 to 48 (valid)
- Size value is greater than 48 (invalid)
- Size value is a whole number (valid)
- Size value is a decimal (invalid)
- Size value is numeric (valid)
- Size value includes nonnumeric characters (invalid)
- Size values entered in ascending order (valid)
- Size values entered in nonascending order (invalid)
- No size values entered (invalid)
- One to five size values entered (valid)
- More than five sizes entered (invalid)
- Item name is first (valid)
- Item name is not first (invalid)
- A single comma separates each entry in list (valid)
- A comma does not separate two or more entries in the list (invalid)
- The entry contains no blanks (???)
- The entry contains blanks (????)
# | 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