You are on page 1of 45

Equivalence Partitioning

- cont’d

1
Equivalence partitioning

Test selection using equivalence partitioning allows a tester


to subdivide the input domain into a relatively small number
of sub-domains, say N>1, as shown (next slide (a)).

In strict mathematical terms, the sub-domains by


definition are disjoint. The four subsets shown in (a)
constitute a partition of the input domain while the subsets
in (b) are not. Each subset is known as an equivalence
class.

2
Subdomains

3
Program behavior and equivalence classes

The equivalence classes are created assuming that the


program under test exhibits the same behavior on all
elements, i.e. tests, within a class.

This assumption allow the tester to select exactly


one test from each equivalence class resulting in a
test suite of exactly N tests.

4
Faults targeted
The entire set of inputs to any application can be divided into
at least two subsets: one containing all the expected, or legal,
inputs (E) and the other containing all unexpected, or illegal,
inputs (U).

Each of the two subsets, can be further subdivided into subsets


on which the application is required to behave differently (e.g.
E1, E2, E3, and U1, U2).

5
Faults targeted (contd.)

Equivalence class partitioning selects tests that target any


faults in the application that cause it to behave incorrectly
when the input is in either of the two classes or their subsets.

6
Unidimensional partitioning
One way to partition the input domain is to consider one input
variable at a time. Thus each input variable leads to a partition
of the input domain. We refer to this style of partitioning as
unidimensional equivalence partitioning or simply
unidimensional partitioning.

This type of partitioning is commonly used.

7
Multidimensional partitioning

Another way is to consider the input domain I as the set


product of the input variables and define a relation on I.
This procedure creates one partition consisting of several
equivalence classes. We refer to this method as
multidimensional equivalence partitioning or simply
multidimensional partitioning.
Multidimensional partitioning leads to a large number of
equivalence classes that are difficult to manage manually.
Many classes so created might be infeasible. Nevertheless,
equivalence classes so created offer an increased variety of
tests as is illustrated in the next section.

8
Partitioning Example

Consider an application that requires two integer inputs x


and y. Each of these inputs is expected to lie in the following
ranges: 3 x7 and 5y9.

For unidimensional partitioning we apply the partitioning


guidelines to x and y individually. This leads to the
following six equivalence classes.

9
Partitioning Example (contd.)

E1: x<3 E2: 3x7 E3: x>7 y ignored.

x ignored.
E4: y<5 E5: 5y9 E6: y>9

For multidimensional partitioning we consider the input


domain to be the set product X x Y. This leads to 9
equivalence classes.

10
Partitioning Example (contd.)

E1: x<3, y<5 E2: x<3, 5y9 E3: x<3, y>9

E4: 3x7, y<5 E5: 3x7, 5y9 E6: 3x7, y>9

E7: >7, y<5 E8: x>7, 5y9 E9: x>7, y>9

11
Partitioning Example (contd.)
6 equivalence classes:

E1: x<3, y<5


E3: x<3, y>9
E2: x<3, 5y9
E4: 3x7, y<5
E5: 3x7, 5y9
E6: 3x7, y>9
E7: >7, y<5
E8: x>7, 5y9
E9: x>7, y>9 9 equivalence classes:
12
Systematic procedure for equivalence partitioning

1. Identify the input domain: Read the requirements carefully


and identify all input and output variables, their types, and any
conditions associated with their use.

Environment variables, such as class variables used in the


method under test and environment variables in Unix,
Windows, and other operating systems, also serve as input
variables. Given the set of values each variable can assume,
an approximation to the input domain is the product of these
sets.

13
Systematic procedure for equivalence partitioning
(contd.)

2. Equivalence classing: Partition the set of values of each


variable into disjoint subsets. Each subset is an equivalence
class. Together, the equivalence classes based on an input
variable partition the input domain. partitioning the input
domain using values of one variable, is done based on the the
expected behavior of the program.

Values for which the program is expected to behave in the ``same


way" are grouped together. Note that ``same way" needs to be
defined by the tester.

14
Systematic procedure for equivalence partitioning
(contd.)

3. Combine equivalence classes: This step is usually omitted and


the equivalence classes defined for each variable are directly
used to select test cases. However, by not combining the
equivalence classes, one misses the opportunity to generate
useful tests.
The equivalence classes are combined using the
multidimensional partitioning approach described earlier.

15
Systematic procedure for equivalence partitioning
(contd.)

4. Identify infeasible equivalence classes: An infeasible


equivalence class is one that contains a combination of input
data that cannot be generated during test. Such an
equivalence class might arise due to several reasons.

For example, suppose that an application is tested via its GUI,


i.e. data is input using commands available in the GUI. The GUI
might disallow invalid inputs by offering a palette of valid
inputs only. There might also be constraints in the requirements
that render certain equivalence infeasible.
16
Boundary value analysis

17
Errors at the boundaries
Experience indicates that programmers make mistakes in
processing values at and near the boundaries of equivalence
classes.
For example, suppose that method M is required to compute a
function f1 when x 0 is true and function f2 otherwise.
However, M has an error due to which it computes f1 for x<0
and f2 otherwise.
Obviously, this fault is revealed, though not necessarily, when
M is tested against x=0 but not if the input test set is, for
example, {-4, 7} derived using equivalence partitioning. In
this example, the value x=0, lies at the boundary of the
equivalence classes x0 and x>0.
18
Boundary value analysis (BVA)

Boundary value analysis is a test selection technique that targets


faults in applications at the boundaries of equivalence classes.

While equivalence partitioning selects tests from within


equivalence classes, boundary value analysis focuses on tests at
and near the boundaries of equivalence classes.

Certainly, tests derived using either of the two techniques may


overlap.

19
BVA

 For each boundary three values are used


 One on the boundary
 One either side of it

20
BVA: Procedure

1 Partition the input domain using unidimensional partitioning.


This leads to as many partitions as there are input variables.
Alternately, a single partition of an input domain can be
created using multidimensional partitioning. We will generate
several sub-domains in this step.

2 Identify the boundaries for each partition. Boundaries may


also be identified using special relationships amongst the
inputs.
3 Select test data such that each boundary value occurs in at
least one test input.
21
BVA: Example: 1. Create equivalence classes

Assuming that an item code must be in the range 99..999 and


quantity in the range 1..100,
Equivalence classes for code:
E1: Values less than 99.
E2: Values in the range.
E3: Values greater than 999.
Equivalence classes for qty:
E4: Values less than 1.
E5: Values in the range.
E6: Values greater than 100.
22
BVA: Example: 2. Identify boundaries
98 100 998 1000
* x * * x *
E1 99 999 E3
E2

0 2 99 101

* x * * x *
E4 1 100 E6
E5

Equivalence classes and boundaries for findPrice. Boundaries are indicated


with an x. Points near the boundary are marked *.

23
BVA: Example: 3. Construct test set

Test selection based on the boundary value analysis


technique requires that tests must include, for each variable,
values at and around the boundary. Consider the following
test set:
T={ t1: (code=98, qty=0),
t2: (code=99, qty=1), Illegal values of code and
qty included.
t3: (code=100, qty=2),
t4: (code=998, qty=99),
t5: (code=999, qty=100),
t6: (code=1000, qty=101)
}
24
BVA: Recommendations

Relationships amongst the input variables must be examined


carefully while identifying boundaries along the input
domain. This examination may lead to boundaries that are
not evident from equivalence classes obtained from the input
and output variables.

Additional tests may be obtained when using a partition of


the input domain obtained by taking the product of
equivalence classes created using individual variables.

25
Boundary Value Testing Example
Boundary Value Testing Example

 Process employment applications based on a person's age.

 Notice the problem at the boundaries. The age "16" is included in two
different equivalence classes (as are 18 and 55).

27
Boundary Value Testing Example (cont)

 Boundary value testing focuses on the boundaries simply because that is where
so many defects hide.

 If (applicantAge >= 0 && applicantAge <=16) hireStatus="NO";

 If (applicantAge >= 16 && applicantAge <=18) hireStatus="PART";

 If (applicantAge >= 18 && applicantAge <=55) hireStatus="FULL";

 If (applicantAge >= 55 && applicantAge <=99) hireStatus="NO";

28
Boundary Value Testing Example (cont)

 Perhaps this is what our organization meant:


0–15 Don't hire
16–17 Can hire on a part-time basis only
18–54 Can hire as full-time employees
55–99 Don't hire

 The requirements do not specify how these values should be treated.

 What about ages -3 and 101?

29
Boundary Value Testing Example (cont)

 The code that implements the corrected rules is:


If (applicantAge >= 0 && applicantAge <=15) hireStatus="NO";
If (applicantAge >= 16 && applicantAge <=17) hireStatus="PART";
If (applicantAge >= 18 && applicantAge <=54) hireStatus="FULL";
If (applicantAge >= 55 && applicantAge <=99) hireStatus="NO";

 The interesting values on or near the boundaries in this example are {-1, 0, 1},
{15, 16, 17}, {17, 18, 19}, {54, 55, 56}, and {98, 99, 100}.

 Other values, such as {-42, 1001, %$#@} might be included depending on the
module's documented preconditions.

30
Robustness Testing

 Extension of boundary value analysis.


 In addition to the five boundary value analysis values of variables, we add
values slightly greater than the maximum (max+) and a value slightly less
than the minimum (min-).
 The extended form of Boundary value is called Robustness Testing

31
Example

Consider a simple program to classify a triangle. Its inputs is a triple of positive integers
(say x, y, z) and the date type for input parameters ensures that these will be integers
greater than 0 and less than or equal to 100. The program output may be one of the
following words:
[Scalene; Isosceles; Equilateral; Not a triangle]
Design the Robustness test cases.

32
The boundary value test cases are shown below:

Test case x y z Expected Output


1 50 50 1 Isosceles
2 50 50 2 Isosceles
3 50 50 50 Equilateral
4 50 50 99 Isosceles
5 50 50 100 Not a triangle
6 50 1 50 Isosceles
7 50 2 50 Isosceles
8 50 99 50 Isosceles
9 50 100 50 Not a triangle
10 1 50 50 Isosceles
11 2 50 50 Isosceles
12 99 50 50 Isosceles
13 100 50 50 Not a triangle
33
For Boundary Value: Test cases: 1, 2, 50, 99, 100 (for all the equivalence classes)
For Robustness : Test Cases: 0, 1, 2, 50, 99, 100, 101 (for all the equivalence classes)
Adding Robustness Test cases
Test case ID x y z Expected Output

14 0 50 50 ?

15 101 50 50 ?

16 50 0 50 ?

17 50 101 50 ?

18 50 50 0 ?

19 50 50 101 ?

6n+1
34
Worst Cases Testing

 If we reject “single fault” assumption theory of reliability and we may like to


see what happens when more than one variable has an extreme value.
 In electronic circuits analysis, this is called “worst case analysis”.
 It requires more effort.

 Worst case testing for a function of n variables generate 5n test cases as


opposed to 4n+1 test cases for boundary value analysis and 6n+1 test cases
for Robustness testing.

35
Example

Consider a simple program to classify a triangle. Its inputs is a triple of positive integers
(say x, y, z) and the date type for input parameters ensures that these will be integers
greater than 0 and less than or equal to 100. The program output may be one of the
following words:
[Scalene; Isosceles; Equilateral; Not a triangle]
Design the Worst Case test cases.

36
Worst Case Testing
Worst test cases are 53 = 125

Test Case x y z Expected output


1 1 1 1 Equilateral
2 1 1 2 Not a triangle
3 1 1 50 Not a triangle
4 1 1 99 Not a triangle
5 1 1 100 Not a triangle
6 1 2 1 Not a triangle
7 1 2 2 Isosceles
8 1 2 50 Not a triangle
9 1 2 99 Not a triangle
10 1 2 100 Not a triangle
11 1 50 1 Not a triangle
12 1 50 2 Not a triangle
13 1 50 50 Isosceles
14 1 50 99 Not a triangle 37
Test Case A b c Expected output
15 1 50 100 Not a triangle
16 1 99 1 Not a triangle
17 1 99 2 Not a triangle
18 1 99 50 Not a triangle
19 1 99 99 Isosceles
20 1 99 100 Not a triangle
21 1 100 1 Not a triangle
22 1 100 2 Not a triangle
23 1 100 50 Not a triangle
24 1 100 99 Not a triangle
25 1 100 100 Isosceles
26 2 1 1 Not a triangle
27 2 1 2 Isosceles
28 2 1 50 Not a triangle
29 2 1 99 Not a triangle
30 2 1 100 Not a triangle 38
31 2 2 1 Isosceles
Test Case A b C Expected output
32 2 2 2 Equilateral
33 2 2 50 Not a triangle
34 2 2 99 Not a triangle
35 2 2 100 Not a triangle
36 2 50 1 Not a triangle
37 2 50 2 Not a triangle
38 2 50 50 Isosceles
39 2 50 99 Not a triangle
40 2 50 100 Not a triangle
41 2 99 1 Not a triangle
42 2 99 2 Not a triangle
43 2 99 50 Not a triangle
44 2 99 99 Isosceles
45 2 99 100 Scalene
46 2 100 1 Not a triangle
39
47 2 100 2 Not a triangle
48 2 100 50 Not a triangle
Test Case A b C Expected output
49 2 100 50 Scalene
50 2 100 99 Isosceles
51 50 1 100 Not a triangle
52 50 1 1 Not a triangle
53 50 1 2 Isosceles
54 50 1 50 Not a triangle
55 50 1 99 Not a triangle
56 50 2 100 Not a triangle
57 50 2 1 Not a triangle
58 50 2 2 Isosceles
59 50 2 50 Not a triangle
60 50 2 99 Not a triangle
61 50 50 100 Isosceles
62 50 50 1 Isosceles
63 50 50 2 Equilateral
40
64 50 50 50 Isosceles
65 50 50 99 Not a triangle
Test Case A B C Expected output
66 50 99 1 Not a triangle
67 50 99 2 Not a triangle
68 50 99 50 Isosceles
69 50 99 99 Isosceles
70 50 99 100 Scalene
71 50 100 1 Not a triangle
72 50 100 2 Not a triangle
73 50 100 50 Not a triangle
74 50 100 99 Scalene
75 50 100 100 Isosceles
76 50 1 1 Not a triangle
77 99 1 2 Not a triangle
78 99 1 50 Not a triangle
79 99 1 99 Isosceles
80 99 1 100 Not a triangle
81 99 2 1 Not a triangle 41
82 99 2 2 Not a triangle
Test Case A b C Expected output
83 99 2 50 Not a triangle
84 99 2 99 Isosceles
85 99 2 100 Scalene
86 99 50 1 Not a triangle
87 99 50 2 Not a triangle
88 99 50 50 Isosceles
89 99 50 99 Isosceles
90 99 50 100 Scalene
91 99 99 1 Isosceles
92 99 99 2 Isosceles
93 99 99 50 Isosceles
94 99 99 99 Equilateral
95 99 99 100 Isosceles
96 99 100 1 Not a triangle
97 99 100 2 Scalene
42
98 99 100 50 Scalene
99 99 100 99 Isosceles
100 99 100 100 Isosceles
Test Case A b C Expected output
101 100 1 1 Not a triangle
102 100 1 2 Not a triangle
103 100 1 50 Not a triangle
104 100 1 99 Not a triangle
105 100 1 100 Isosceles
106 100 2 1 Not a triangle
107 100 2 2 Not a triangle
108 100 2 50 Not a triangle
109 100 2 99 Scalene
110 100 2 100 Isosceles
111 100 50 1 Not a triangle
112 100 50 2 Not a triangle
113 100 50 50 Not a triangle
114 100 50 99 Scalene
115 100 50 100 Isosceles
116 100 99 1 Not a triangle
43
117 100 99 2 Scalene
118 100 99 50 Scalene
Test Case A b C Expected output
119 100 99 99 Isosceles
120 100 99 100 Isosceles
121 100 100 1 Isosceles
122 100 100 2 Isosceles
123 100 100 50 Isosceles
124 100 100 99 Isosceles
125 100 100 100 Equilateral

44
Exercise

Consider a program for determining the Previous date. Its input is a triple of day,
month and year with the values in the range
1 ≤ month ≤ 12
1 ≤ day ≤ 31
1900 ≤ year ≤ 2025
The possible outputs would be Previous date or invalid input date.
Design the Robustness and worst case test cases.

45

You might also like