Chapter3

Chapter 3: Equivalence Class Testing :EC
322235 Software Testing
By
Asst.Prof.Dr. Wararat Songpan (Rungworawut)
Department of Computer Science,
Faculty of Science,
Khon Kaen University, Thailand
1
Equivalence Class Testing : EC
•
•
•
The next step from Boundary Value Testing is a
Functional Testing.
Define equivalence classes on the range of input or
output for each variables also called partition
method.
Completeness and greatly reduces redundancy.
2
Equivalence Class Testing : EC
• Function F is implemented and a function F, of two
variables x1 and x2.
• x1 and x2 have the following boundaries and
intervals within boundaries:
▫ a=<x1=<d with intervals [a,b), [b,c), [c,d]
▫ e=<x2=<g with intervals [e,f), [f,g]
• So, invalid value for x1 and x2 as follows,
▫ x1 < a and x1>d
▫ x2 <e and x2>g
Remarks: [ = closed interval, ( = open interval
3
Equivalence Class Testing : EC
There are 4 sub-techniques of Equivalence Class Testing.
1) Weak Normal Testing :WN
2) Strong Normal Testing :SN
3) Weak Robust Testing :WR
4) Strong Robust Testing :SR
4
1) Weak Normal Testing :WN
Valid EC:
x2
Ec1 = {x1: a=<x1< b}
Ec2= {x1: b=<x1< c}
g
Ec3 = {x1: c <= x1 <= d}
f
Ec4 = {x2: e =<x2 < f}
e
Ec5 = {x2: f =< x2 <=g}
x1
a
b
c
d
-One variable from each equivalence class as “single fault assumption”
-Values identified in systematic way
5
For example: Addition x1 and x2
(Simple example)
Function: Addition X1 and x2
x1
x2
Results =
Ok
Cancel
6
Simple example: WN Test case design
x2
Valid EC:
Ec1 = {x1: 5=<x1< 10}
20
Ec2= {x1: 10=<x1< 15}
10
Ec3 = {x1: 15 <= x1 <= 20}
5
Ec4 = {x2: 5 =<x2 <10}
x1
5
Ec5 = {x2: 10=< x2 <=20}
10
15
20
Test case ID
EC ID
x1
x2
Expected Results
WN1
EC1, EC4
5
6
11
WN2
EC2, EC5
12
15
27
WN3
EC3, EC4
17
7
24
7
2) Strong Normal Testing : SN
x2
g
f
e
x1
a
b
c
d
• Test cases taken from each element of Cartesian
product of the equivalence classes. Cartesian product
guarantees notion of completeness.
• SN is a “multiple fault assumption”
8
Simple example: SN Test case design
x2
Valid EC:
Ec1 = {x1: 5=<x1< 10}
20
Ec2= {x1: 10=<x1< 15}
10
Ec3 = {x1: 15 <= x1 <= 20}
5
Ec4 = {x2: 5 =<x2 <10}
x1
Ec5 = {x2: 10=< x2 <=20}
5
10
15
20
Test case ID
EC ID
x1
x2
Expected Results
SN1
EC1, EC4
5
6
11
SN2
EC1, EC5
7
12
19
SN3
EC2, EC4
10
5
15
SN4
EC2, EC5
12
15
27
SN5
EC3, EC4
17
7
24
SN6
EC3, EC5
15
15
30
9
3) Weak Robust Testing (WR)
x2
Additional consider in Invalid EC:
Ec6 = {x1: x1 < a}
g
Ec7 = {x1: x1 > d}
f
Ec8 = {x2 : x2 < e}
Ec9 = {x2 : x2 > g}
e
x1
a
b
c
d
• Robust - consideration of invalid values and extension to WN.
• Invalid inputs – each test case has one invalid value, single
fault should cause failure as “single fault assumption”.
• Problems with robust EC Testing specification (expected
output for invalid TC?)
10
Simple example: WR Test case design
Test case ID
EC ID
x1
x2
Expected Results
WR1
EC1, EC4
5
6
11
WR2
EC2, EC5
12
15
27
WR3
EC3, EC4
17
7
24
WR4
EC6, EC4
4
8
X1 is out of range
WR5
EC7, EC4
23
8
X1 is out of range
WR6
EC3, EC8
18
4
X2 is out of range
WR7
EC3, EC9
18
23
X2 is out of range
11
4) Strong Robust Testing :SR
x2
g
f
e
a
b
c
d
x1
• Robust - consideration of invalid values and
extension to SN.
• Strong – multiple faults assumption.
• Test cases taken from each element of Cartesian
product of the Valid EC and Invalid EC
12
Triangle Program (Simple)
• Input 3 integers: a, b, c are side of triangle that
have boundaries
• a, b, c are [1,200].
• Output is type of triangle
o Equilateral
o Isosceles
o Scalene
o Not a Triangle
13
WN Test case design
Triangle Program (Simple)
Valid EC
• EC1: 1<=a<= 200
• EC2: 1<=b<=200
• EC3: 1<=c<=200
Test Case
EC ID
a
b
c
Expected Results
WN1
EC1,2,3
10
20
30
Scalene
14
SN Test case design
Triangle Program (Simple)
Valid EC
• EC1: 1<=a< 200
• EC2: 1<=b<=200
• EC3: 1<=c<=200
Test Case
EC
a
b
c
Expected Results
SN1
EC1,2,3
10
20
30
Scalene
15
Equivalence Class :
Triangle Problem (Output)
• Using output from specification translate into Equivalence Class (EC)
• 4 possible outputs: Equilateral, Isosceles, Scalene, and Not a Triangle
• 4 output equivalence classes:
o Ec1 = {<a,b,c> : the triangle with sides a, b and c is equilateral}
o Ec2 = {<a,b,c> : the triangle with sides a, b and c is Isosceles}
o Ec3 = {<a,b,c> : the triangle with sides a, b and c is Scalene) }
o Ec4 = {<a,b,c> : the triangle with sides a, b and c is Not a Triangle}
16
Weak Normal(WN)/ Strong Normal(SN)
Test Cases: Triangle Program
Test Case
ID
EC
a
b
c
Expected Results
OWN1
OWN2
OWN3
EC1
EC2
EC3
5
2
3
5
2
4
5
3
5
Equilateral
Isosceles
Scalene
OWN4
EC4
4
1
2
Not a
Triangle
17
Weak Robust(WR) Test Cases: Triangle Program
Consideration Invalid EC with WN
• EC5: a> 200
• EC6: a < 1
• EC7: b>200
• EC8: b < 1
• EC9: c>200
• EC10: c<1
18
Weak Robust(WR) Test Cases: Triangle Program
EC
a
b
c
Expected Results
WR1
EC6
-1
5
5
a not in range
WR2
EC8
5
-1
5
b not in range
WR3
EC10
5
5
-1
c not in range
WR4
EC5
201
5
5
a not in range
WR5
EC7
5
201
5
b not in range
WR6
EC9
5
5
201
c not in range
Test
Case ID
WN1
…WN4
19
Strong Robust(SR) Test Cases: Triangle Program
Test Case
WN1
…WN4
SR1
SR2
SR3
SR4
SR5
SR6
SR7
a
b
c
Expected Results
-1
5
5
-1
5
-1
-1
5
-1
5
-1
-1
5
-1
5
5
-1
5
-1
-1
-1
a not in range
b not in range
c not in range
a, b not in range
b, c not in range
a, c not in range
a, b, c not in range
20
Improved EC:
Triangle Program
 Improved EC Input classes for each type
of triangle:
▫
▫
▫
▫
▫
EC1 = {<a, b, c>: a=b=c}
EC2 = {<a, b, c>: a=b, a ≠ c}
EC3 = {<a, b, c>: a=c, a ≠ b}
EC4 = {<a, b, c>: b=c, a ≠ b}
EC5 = {<a, b, c>: a ≠ b, a ≠ c, b ≠ c }
 Extra design of input classes: Check every
side of triangle as not a triangle
▫ EC6 = {<a, b, c>: b + c <= a}
▫ EC7 = {<a, b, c>: a + c <= b}
▫ EC8 = {<a, b, c>: a + b <= c}
21
Equivalence Classes(EC) :
NextDate Problem
• Valid EC
o M1 = {month: 1 =< month =<12}
o D1 = {day: 1 =< day =< 31}
o Y1 = {year: 1812 =< year =< 2012}
• Invalid EC
o M2 = {month: month <1}
o M3 = {month: month >12}
o D2 = {day: day <1}
o D3 = {day: day >31}
o Y2 = {year: year < 1812}
o Y3 = {year: year > 2012}
22
Weak Normal and Strong Normal
Test Cases: NextDate Problem
Test Case
Month
Day
Year
Expected Results
WN1, SN1
6
15
1912
6/16/1912
23
Weak Robust Test Cases: The
NextDate Problem
Test Case
ID
Month
Day
Year
Expected Results
WN1
6
15
1912
6/16/1912
WR1
-1
15
1912
Month not in range 1…12
WR2
13
15
1912
Month not in range 1…12
WR3
6
-1
1912
Day not in range 1…31
WR4
6
32
1912
Day not in range 1…31
WR5
6
15
1811
Year not in range 1812…2012
WR6
6
15
2013
Year not in range 1812…2012
24
Strong Robust Test Cases:
The NextDate Problem
Test Case
Month
Day
Year
Expected Results
WN1
6
15
1912
6/16/1912
SR1
-1
15
1912
month not in range 1…12
SR2
6
-1
1912
day not in range 1…31
SR3
6
15
1811
year not in range 1812…2012
SR4
-1
-1
1912
month not in range 1…12
day not in range 1…31
SR5
6
-1
1811
day not in range 1…31
year not in range 1812…2012
SR6
-1
15
1811
month not in range 1…12
year not in range 1812…2012
SR7
-1
-1
1811
month not in range 1…12
day not in range 1…31
year not in range 1812…2012
25
Improved Input Equivalence
Classes: NextDate Problem
• M1 = {month: month has 30 days}
• M2 = {month: month has 31 days}
•
•
•
•
•
•
•
M3 = {month: month = February}
D1 = {day: 1 =< day =< 28}
D2 = {day: day = 29}
D3 = {day: day = 30}
D4 = {day: day = 31}
Y1 = {year: year is leap year}
Y2 = {year: year is common year }
26
Input Equivalence Class: The
Commission Problem
Valid EC
• L1 = {lock: 1 =< locks =< 70}
• S1 = {stocks: 1=< stocks =< 80}
• B1 = {barrels: 1 =< barrels =< 90}
Invalid EC
• L2 = {locks: locks <1}
• L3 = {locks: locks > 70}
• S2 = {stocks: stocks < 1}
• S3 = {stocks: stocks > 80}
• B2 = {barrels: barrels <1}
• B3 = {barrels: barrels >90}
27
Strong Robust Test Cases: Commission Problem
Test Case ID
Locks
Stocks
Barrels
Expected Results
SR1
5
5
5
50
SR2
-1
40
45
Locks not in range 1…70
SR3
35
-1
45
Stocks not in range 1…80
SR4
35
40
-1
Barrels not in range 1…90
SR5
-1
-1
45
Locks not in range 1…70
Stocks not in range 1…80
SR6
-1
40
-1
Locks not in range 1…70
Barrels not in range 1…90
SR7
35
-1
-1
Stocks not in range 1…80
Barrels not in range 1…90
SR8
-1
-1
-1
Locks not in range 1…70
Stocks not in range 1…80
Barrels not in range 1…90
28
Using output to Equivalence Classes Test
Cases: Commission Problem
• Sales = 45 * locks +30 * stocks + 25 * barrels
o S1 = {<locks, stocks, barrels>: sales =<1000}
o S2 = {<locks, stocks, barrels>: 1000 < sales =<1800}
o S3 = {<locks, stocks, barrels>: sales > 1800 }
How to design WN Test Case??
Test
Case ID
Locks
Stocks
Barrels
Sales
Commission
(Expected
Results)
OWN1
5
5
5
500
50
OWN2
15
15
15
1500
175
OWN3
25
25
25
2500
360
29
Specification of Commission
Sales = 45*Locks + 30*Stock + 25*barrels
if sales <= 1000
commission = 10% * sales
if sales > 1000
commission = 10%*1000 + 15%*(sales – 1000)
if sales > 1800
commission = 10%*1000+ 15%*800+ 20%*
(sales-1800)
30
Summary of EC Testing
Normal vs Robust
Normal (Valid)
Robust (Valid +Invalid)
Weak Normal Testing
Strong Normal Testing
Weak Robust Testing
Strong Robust Testing
Single fault vs Multiple fault assumption
Single fault (1 EC)
Multiple fault (1 EC+)
Weak Normal Testing
Weak Robust Testing
Strong Normal Testing
Strong Robust Testing
31