Understanding Software Testing Concepts
Understanding Software Testing Concepts
K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 1
Software Testing
• What is Testing?
Many people understand many definitions of testing :
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 2
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 3
Software Testing
In the software life cycle the earlier the errors are discovered and removed,
the lower is the cost of their removal.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 4
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 5
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 6
Software Testing
The number of paths in the example of Fig. 1 are 1014 or 100 trillions. It is
computed from 520 + 519 + 518 + …… + 51; where 5 is the number of paths
through the loop body. If only 5 minutes are required to test one test path, it
may take approximately one billion years to execute every path.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 8
Software Testing
Some Terminologies
➢ Error, Mistake, Bug, Fault and Failure
People make errors. A good synonym is mistake. This may be a syntax
error or misunderstanding of specifications. Sometimes, there are logical
errors.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 9
Software Testing
➢ Test, Test Case and Test Suite
Test and Test case terms are used interchangeably. In practice, both are
same and are treated as synonyms. Test case describes an input
description and an expected output description.
Test Case ID
Section-I Section-II
(Before Execution) (After Execution)
Purpose : Execution History:
Pre condition: (If any) Result:
Inputs: If fails, any possible reason (Optional);
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 11
Software Testing
➢ Alpha, Beta and Acceptance Testing
The term Acceptance Testing is used when the software is developed for
a specific customer. A series of tests are conducted to enable the customer
to validate all requirements. These tests are conducted by the end user /
customer and may range from adhoc tests to well planned systematic
series of tests.
The terms alpha and beta testing are used when the software is developed
as a product for anonymous customers.
Alpha Tests are conducted at the developer’s site by some potential
customers. These tests are conducted in a controlled environment. Alpha
testing may be started when formal testing process is near completion.
Beta Tests are conducted by the customers / end users at their sites.
Unlike alpha testing, developer is not present here. Beta testing is
conducted in a real environment that cannot be controlled by the developer.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 12
Software Testing
Functional Testing
Input Output
domain domain
System
Input test Output
under
data test data
test
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 13
Software Testing
Boundary Value Analysis
Consider a program with two input variables x and y. These input variables
have specified boundaries as:
a≤x≤b
c≤y≤d
Input domain
d
y
c
a b
x
Fig.4: Input domain for program having two input variables
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 14
Software Testing
The boundary value analysis test cases for our program with two inputs
variables (x and y) that may have any value from 100 to 300 are: (200,100),
(200,101), (200,200), (200,299), (200,300), (100,200), (101,200), (299,200) and
(300,200). This input domain is shown in Fig. 8.5. Each dot represent a test case
and inner rectangle is the domain of legitimate inputs. Thus, for a program of n
variables, boundary value analysis yield 4n + 1 test cases.
Input domain
400
300
y 200
100
Example- 8.I
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 16
Software Testing
Solution
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 17
Software Testing
The boundary value test cases are :
Test Case a b c Expected output
1 0 50 50 Not Quadratic
2 1 50 50 Real Roots
3 50 50 50 Imaginary Roots
4 99 50 50 Imaginary Roots
5 100 50 50 Imaginary Roots
6 50 0 50 Imaginary Roots
7 50 1 50 Imaginary Roots
8 50 99 50 Imaginary Roots
9 50 100 50 Equal Roots
10 50 50 0 Real Roots
11 50 50 1 Real Roots
12 50 50 99 Imaginary Roots
13 50 50 100 Imaginary Roots
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 18
Software Testing
Example – 8.2
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
boundary value test cases.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 19
Software Testing
Solution
The Previous date program takes a date as input and checks it for validity.
If valid, it returns the previous date as its output.
With single fault assumption theory, 4n+1 test cases can be designed and
which are equal to 13.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 20
Software Testing
The boundary value test cases are:
Test Case Month Day Year Expected output
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 21
Software Testing
Example – 8.3
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 22
Software Testing
Solution
The boundary value test cases are shown below:
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
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 23
Software Testing
Robustness testing
It is nothing but the extension of boundary value analysis. Here, we would
like to see, what happens when the extreme values are exceeded with a
value slightly greater than the maximum, and a value slightly less than
minimum. It means, we want to go outside the legitimate boundary of input
domain. This extended form of boundary value analysis is called
robustness testing and shown in Fig. 6
There are four additional test cases which are outside the legitimate input
domain. Hence total test cases in robustness testing are 6n+1, where n is
the number of input variables. So, 13 test cases are:
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 24
Software Testing
400
300
y 200
100
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 25
Software Testing
Worst-case testing
If we reject “single fault” assumption theory of reliability and 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 is more
thorough in the sense that boundary value test cases are a proper subset
of worst case test cases. 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. Our two variables example will have
52=25 test cases and are given in table 1.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 26
Software Testing
Table 1: Worst cases test inputs for two variables example
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 27
Software Testing
Example - 8.4
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 28
Software Testing
Solution
Robust test cases are 6n+1. Hence, in 3 variable input cases total number
of test cases are 19 as given on next slide:
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 29
Software Testing
Test case a b c Expected Output
1 -1 50 50 Invalid input`
3 1 50 50 Real roots
4 50 50 50 Imaginary roots
5 99 50 50 Imaginary roots
6 100 50 50 Imaginary roots
7 101 50 50 Invalid input
8 50 -1 50 Invalid input
9 50 0 50 Imaginary roots
10 50 1 50 Imaginary roots
11 50 99 50 Imaginary roots
12 50 100 50 Equal roots
15 50 50 0 Real roots
16 50 50 1 Real roots
17 50 50 99 Imaginary roots
18 50 50 100 Imaginary roots
19 50 50 101 Invalid input
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 30
Software Testing
In case of worst test case total test cases are 5n. Hence, 125 test cases will be
generated in worst test cases. The worst test cases are given below:
Test Case a b c Expected output
1 0 0 0 Not Quadratic
2 0 0 1 Not Quadratic
3 0 0 50 Not Quadratic
4 0 0 99 Not Quadratic
5 0 0 100 Not Quadratic
6 0 1 0 Not Quadratic
7 0 1 1 Not Quadratic
8 0 1 50 Not Quadratic
9 0 1 99 Not Quadratic
10 0 1 100 Not Quadratic
11 0 50 0 Not Quadratic
12 0 50 1 Not Quadratic
13 0 50 50 Not Quadratic
14 0 50 99 Not Quadratic
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 31
Software Testing
Test Case A b c Expected output
32 1 1 1 Imaginary
33 1 1 50 Imaginary
34 1 1 99 Imaginary
35 1 1 100 Imaginary
36 1 50 0 Real Roots
37 1 50 1 Real Roots
38 1 50 50 Real Roots
39 1 50 99 Real Roots
40 1 50 100 Real Roots
41 1 99 0 Real Roots
42 1 99 1 Real Roots
43 1 99 50 Real Roots
44` 1 99 99 Real Roots
45 1 99 100 Real Roots
46 1 100 0 Real Roots
47 1 100 1 Real Roots
48 1 100 50 Real Roots
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 33
Software Testing
Test Case A b C Expected output
66 50 99 0 Real Roots
67 50 99 1 Real Roots
68 50 99 50 Imaginary
69 50 99 99 Imaginary
70 50 99 100 Imaginary
71 50 100 0 Real Roots
72 50 100 1 Real Roots
73 50 100 50 Equal Roots
74 50 100 99 Imaginary
75 50 100 100 Imaginary
76 99 0 0 Equal Roots
77 99 0 1 Imaginary
78 99 0 50 Imaginary
79 99 0 99 Imaginary
80 99 0 100 Imaginary
81 99 1 0 Real Roots
82 99 1 1 Imaginary
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 35
Software Testing
Test Case A b C Expected output
83 99 1 50 Imaginary
84 99 1 99 Imaginary
85 99 1 100 Imaginary
86 99 50 0 Real Roots
87 99 50 1 Real Roots
88 99 50 50 Imaginary
89 99 50 99 Imaginary
90 99 50 100 Imaginary
91 99 99 0 Real Roots
92 99 99 1 Real Roots
93 99 99 50 Imaginary Roots
94 99 99 99 Imaginary
95 99 99 100 Imaginary
96 99 100 0 Real Roots
97 99 100 1 Real Roots
98 99 100 50 Imaginary
99 99 100 99 Imaginary
100 99 100 100 Imaginary
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 36
Software Testing
Test Case A b C Expected output
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 37
Software Testing
Test Case A b C Expected output
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 38
Software Testing
Example – 8.5
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 39
Software Testing
Solution
Robust test cases are 6n+1. Hence total 19 robust test cases are designed
and are given on next slide.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 40
Software Testing
Test case Month Day Year Expected Output
1 6 15 1899 Invalid date (outside range)
2 6 15 1900 14 June, 1900
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 42
Software Testing
Test Case A b c Expected output
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 47
Software Testing
Test Case Month Day Year Expected output
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 49
Software Testing
Example – 8.6
Consider the triangle problem as given in example 8.3. Generate robust and
worst test cases for this problem.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 50
Software Testing
Solution
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 51
Software Testing
` x y z Expected Output
1 50 50 0 Invalid input`
2 50 50 1 Isosceles
3 50 50 2 Isosceles
4 50 50 50 Equilateral
5 50 50 99 Isosceles
6 50 50 100 Not a triangle
15 1 50 50 Isosceles
16 2 50 50 Isosceles
17 99 50 50 Isosceles
18 100 50 50 Not a triangle
19 100 50 50 Invalid input
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 52
Software Testing
Worst test cases are 125 and are given below:
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
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 53
Software Testing
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
47 2 100 2 Not a triangle
48 2 100 50 Not a triangle
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 55
Software Testing
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
64 50 50 50 Isosceles
65 50 50 99 Not a triangle
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 56
Software Testing
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
82 99 2 2 Not a triangle
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 57
Software Testing
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
98 99 100 50 Scalene
99 99 100 99 Isosceles
100 99 100 100 Isosceles
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 58
Software Testing
Test Case A b C Expected output
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 59
Software Testing
Test Case A b C Expected output
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 60
Software Testing
Equivalence Class Testing
In this method, input domain of a program is partitioned into a finite number of
equivalence classes such that one can reasonably assume, but not be
absolutely sure, that the test of a representative value of each class is
equivalent to a test of any other value.
Two steps are required to implementing this method:
1. The equivalence classes are identified by taking each input condition and
partitioning it into valid and invalid classes. For example, if an input
condition specifies a range of values from 1 to 999, we identify one valid
equivalence class [1<item<999]; and two invalid equivalence classes
[item<1] and [item>999].
2. Generate the test cases using the equivalence classes identified in the
previous step. This is performed by writing test cases covering all the valid
equivalence classes. Then a test case is written for each invalid equivalence
class so that no test contains more than one invalid class. This is to ensure
that no two invalid classes mask each other.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 61
Software Testing
Invalid input
Valid System
Outputs
inputs under test
Most of the time, equivalence class testing defines classes of the input domain.
However, equivalence classes should also be defined for output domain.
Hence, we should design equivalence classes based on input and output
domain.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 62
Software Testing
Example 8.7
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 63
Software Testing
Solution
Output domain equivalence class test cases can be identified as follows:
O1={<a,b,c>:Not a quadratic equation if a = 0}
O1={<a,b,c>:Real roots if (b2-4ac)>0}
O1={<a,b,c>:Imaginary roots if (b2-4ac)<0}
O1={<a,b,c>:Equal roots if (b2-4ac)=0}`
The number of test cases can be derived form above relations and shown
below:
Test case a b c Expected output
1 0 50 50 Not a quadratic equation
2 1 50 50 Real roots
3 50 50 50 Imaginary roots
4 50 100 50 Equal roots
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 64
Software Testing
We may have another set of test cases based on input domain.
I1= {a: a = 0}
I2= {a: a < 0}
I3= {a: 1 ≤ a ≤ 100}
I4= {a: a > 100}
I5= {b: 0 ≤ b ≤ 100}
I6= {b: b < 0}
I7= {b: b > 100}
I8= {c: 0 ≤ c ≤ 100}
I9= {c: c < 0}
I10={c: c > 100}
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 65
Software Testing
Here test cases 5 and 8 are redundant test cases. If we choose any value other
than nominal, we may not have redundant test cases. Hence total test cases are
10+4=14 for this problem.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 66
Software Testing
Example 8.8
Consider the program for determining the previous date in a calendar as
explained in example 8.3. Identify the equivalence class test cases for output
& input domains.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 67
Software Testing
Solution
Output domain equivalence class are:
O1={<D,M,Y>: Previous date if all are valid inputs}
O1={<D,M,Y>: Invalid date if any input makes the date invalid}
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 68
Software Testing
We may have another set of test cases which are based on input domain.
I1={month: 1 ≤ m ≤ 12}
I2={month: m < 1}
I3={month: m > 12}
I4={day: 1 ≤ D ≤ 31}
I5={day: D < 1}
I6={day: D > 31}
I7={year: 1900 ≤ Y ≤ 2025}
I8={year: Y < 1900}
I9={year: Y > 2025}
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 69
Software Testing
Inputs domain test cases are :
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 70
Software Testing
Example – 8.9
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 71
Software Testing
Solution
Output domain equivalence classes are:
1 50 50 50 Equilateral
2 50 50 99 Isosceles
3 100 99 50 Scalene
4 50 100 50 Not a triangle
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 72
Software Testing
Input domain based classes are:
I1={x: x < 1}
I2={x: x > 100}
I3={x: 1 ≤ x ≤ 100}
I4={y: y < 1}
I5={y: y > 100}
I6={y: 1 ≤ y ≤ 100}
I7={z: z < 1}
I8={z: z > 100}
I9={z: 1 ≤ z ≤ 100}
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 73
Software Testing
Some inputs domain test cases can be obtained using the relationship amongst x,y
and z.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 74
Software Testing
Test cases derived from input domain are:
1 0 50 50 Invalid input
2 101 50 50 Invalid input
3 50 50 50 Equilateral
4 50 0 50 Invalid input
5 50 101 50 Invalid input
6 50 50 50 Equilateral
7 50 50 0 Invalid input
8 50 50 101 Invalid input
9 50 50 50 Equilateral
10 60 60 60 Equilateral
11 50 50 60 Isosceles
12 50 60 50 Isosceles
13 60 50 50 Isosceles
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 75
Software Testing
14 100 99 50 Scalene
15 100 50 50 Not a triangle
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 76
Software Testing
Decision Table Based Testing
Condition Entry
Stub
True False
C1
True False True False
C2
Action a1 X X X
Stub
a2
X X X
a3
X X
a4
X X X
Conditions F T T T T T T T T T T
C1 : x < y + z ?
C2 : y < x + z ? -- F T T T T T T T T T
C3 : z < x + y ? -- -- F T T T T T T T T
C4 : x = y ? -- -- -- T T T T F F F F
C5 : x = z ? -- -- -- T T F F T T F F
C6 : y = z ? -- -- -- T F T F T F T F
a1 : Not a triangle X X X
a2 : Scalene X
a3 : Isosceles X X X
a4 : Equilateral X
a5 : Impossible X X X
Example 8.10
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 80
Software Testing
Solution
There are eleven functional test cases, three to fail triangle property, three
impossible cases, one each to get equilateral, scalene triangle cases, and
three to get on isosceles triangle. The test cases are given in Table 5.
Test case x y z Expected Output
1 4 1 2 Not a triangle
2 1 4 2 Not a triangle
3 1 2 4 Not a triangle
4 5 5 5 Equilateral
5 ? ? ? Impossible
6 ? ? ? Impossible
7 2 2 3 Isosceles
8 ? ? ? Impossible
9 2 3 2 Isosceles
10 3 2 2 Isosceles
11 3 4 5 Scalene
Consider a program for the determination of 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 are “Previous date” and “Invalid date”. Design the test cases
using decision table based testing.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 82
Software Testing
Solution
The input domain can be divided into following classes:
I1= {M1: month has 30 days}
I2= {M2: month has 31 days except March, August and January}
I3= {M3: month is March}
I4= {M4: month is August}
I5= {M5: month is January}
I6= {M6: month is February}
I7= {D1: day = 1}
I8= {D2: 2 ≤ day ≤ 28}
I9= {D3: day = 29}
I10={D4: day = 30}
I11={D5: day = 31}
I12={Y1: year is a leap year}
I13={Y2: year is a common year}
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 83
Software Testing
The decision table is given below:
[Link]. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
C1: Months in M1 M1 M1 M1 M1 M1 M1 M1 M1 M1 M2 M2 M2 M2 M2
C2: days in D1 D1 D2 D2 D3 D3 D4 D4 D5 D5 D1 D1 D2 D2 D3
C3: year in Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1
a1: Impossible X X
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 84
Software Testing
[Link]. 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
C1: Months in M2 M2 M2 M2 M2 M3 M3 M3 M3 M3 M3 M3 M3 M3 M3
C2: days in D3 D4 D4 D5 D5 D1 D1 D2 D2 D3 D3 D4 D4 D5 D5
C3: year in Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2
a1: Impossible
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 85
Software Testing
[Link]. 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
C1: Months in M4 M4 M4 M4 M4 M4 M4 M4 M4 M4 M5 M5 M5 M5 M5
C2: days in D1 D1 D2 D2 D3 D3 D4 D4 D5 D5 D1 D1 D2 D2 D3
C3: year in Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1
a1: Impossible
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 86
Software Testing
[Link]. 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
C1: Months in M5 M5 M5 M5 M5 M6 M6 M6 M6 M6 M6 M6 M6 M6 M6
C2: days in D3 D4 D4 D5 D5 D1 D1 D2 D2 D3 D3 D4 D4 D5 D5
C3: year in Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2 Y1 Y2
a1: Impossible X X X X X
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 87
Software Testing
Test case Month Day Year Expected output
1 June 1 1964 31 May, 1964
2 June 1 1962 31 May, 1962
3 June 15 1964 14 June, 1964
4 June 15 1962 14 June, 1962
5 June 29 1964 28 June, 1964
6 June 29 1962 28 June, 1962
7 June 30 1964 29 June, 1964
8 June 30 1962 29 June, 1962
9 June 31 1964 Impossible
10 June 31 1962 Impossible
11 May 1 1964 30 April, 1964
12 May 1 1962 30 April, 1962
13 May 15 1964 14 May, 1964
14 May 15 1962 14 May, 1962
15 May 29 1964 28 May, 1964
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 88
Software Testing
Test case Month Day Year Expected output
16 May 29 1962 28 May, 1962
17 May 30 1964 29 May, 1964
18 May 30 1962 29 May, 1962
19 May 31 1964 30 May, 1964
20 May 31 1962 30 May, 1962
21 March 1 1964 29 February, 1964
22 March 1 1962 28 February, 1962
23 March 15 1964 14 March, 1964
24 March 15 1962 14 March, 1962
25 March 29 1964 28 March, 1964
26 March 29 1962 28 March, 1962
27 March 30 1964 29 March, 1964
28 March 30 1962 29 March, 1962
29 March 31 1964 30 March, 1964
30 March 31 1962 30 March, 1962
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 89
Software Testing
Test case Month Day Year Expected output
31 August 1 1964 31 July, 1962
32 August 1 1962 31 July, 1964
33 August 15 1964 14 August, 1964
34 August 15 1962 14 August, 1962
35 August 29 1964 28 August, 1964
36 August 29 1962 28 August, 1962
37 August 30 1964 29 August, 1964
38 August 30 1962 29 August, 1962
39 August 31 1964 30 August, 1964
40 August 31 1962 30 August, 1962
41 January 1 1964 31 December, 1964
42 January 1 1962 31 December, 1962
43 January 15 1964 14 January, 1964
44 January 15 1962 14 January, 1962
45 January 29 1964 28 January, 1964
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 90
Software Testing
Test case Month Day Year Expected output
46 January 29 1962 28 January, 1962
47 January 30 1964 29 January, 1964
48 January 30 1962 29 January, 1962
49 January 31 1964 30 January, 1964
50 January 31 1962 30 January, 1962
51 February 1 1964 31 January, 1964
52 February 1 1962 31 January, 1962
53 February 15 1964 14 February, 1964
54 February 15 1962 14 February, 1962
55 February 29 1964 28 February, 1964
56 February 29 1962 Impossible
57 February 30 1964 Impossible
58 February 30 1962 Impossible
59 February 31 1964 Impossible
60 February 31 1962 Impossible
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 91
Software Testing
Cause Effect Graphing Technique
▪ Consider single input conditions
▪ do not explore combinations of input circumstances
Steps
1. Causes & effects in the specifications are identified.
A cause is a distinct input condition or an equivalence class of input conditions.
5. The columns in the decision table are converted into test cases.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 92
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 93
Software Testing
Myers explained this effectively with following example. “The characters in column 1
must be an A or B. The character in column 2 must be a digit. In this situation, the
file update is made. If the character in column 1 is incorrect, message x is issued. If
the character in column 2 is not a digit, message y is issued”.
The causes are
c1: character in column 1 is A
c2: character in column 1 is B
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 94
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 95
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 96
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 98
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 99
Software Testing
Example 8.12
Consider the triangle problem specified in the example 8.3. Draw the Cause
effect graph and identify the test cases.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 100
Software Testing
Solution
The causes are
c1: side x is less than sum of sides y and z
c2: side y is less than sum of sides x and y
c3: side z is less than sum of sides x and y
c4: side x is equal to side y
c5: side x is equal to side z
c6: side y is equal to side z
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 101
Software Testing
The cause effect graph is shown in fig. 13 and decision table is shown in table 6.
The test cases for this problem are available in Table 5.
Conditions
C1: x < y + z ? 0 1 1 1 1 1 1 1 1 1 1
C2: y < x + z ? X 0 1 1 1 1 1 1 1 1 1
C3: z < x + y ? X X 0 1 1 1 1 1 1 1 1
C4: x = y ? X X X 1 1 1 1 0 0 0 0
C5: x = z ? X X X 1 1 0 0 1 1 0 0
C6: y = z ? X X X 1 0 1 0 1 0 1 0
e1: Not a triangle 1 1 1
e2: Scalene 1
e3: Isosceles 1 1 1
e4: Equilateral 1
e5: Impossible 1 1 1
Path Testing
Path testing is the name given to a group of test techniques based on judiciously
selecting a set of test paths through the program. If the set of paths is properly
chosen, then it means that we have achieved some measure of test thoroughness.
2. finding a set of test cases that will execute every path in the set of program
paths.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 104
Software Testing
Flow Graph
The control flow of a program can be analysed using a graphical representation
known as flow graph. The flow graph is a directed graph in which nodes are either
entire statements or fragments of a statement, and edges represents flow of control.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 105
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 106
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 107
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 108
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 109
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 111
Software Testing
DD Path Graph
Table 7: Mapping of flow graph nodes and DD path nodes
Flow graph DD Path graph Remarks
nodes corresponding
node
1 to 9 n1 There is a sequential flow from node 1 to 9
10 n2 Decision node, if true go to 13 else go to 44
11 n3 Decision node, if true go to 12 else go to 19
12 n4 Decision node, if true go to 13 else go to 15
13,14 n5 Sequential nodes and are combined to form new node n5
15,16,17 n6 Sequential nodes
18 n7 Edges from node 14 to 17 are terminated here
19 n8 Decision node, if true go to 20 else go to 37
20 n9 Intermediate node with one input edge and one output edge
21 n10 Decision node, if true go to 22 else go to 27
22 n11 Intermediate node
23 n12 Decision node, if true go to 24 else go to 26
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 11.2
Cont…
Software Testing
Cont….
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 113
Software Testing
Flow graph DD Path graph Remarks
nodes corresponding
node
44 n25 Decision node, if true go to 45 else go to 82. Three edges from 18,43 & 10
are also terminated here.
45 n26 Decision node, if true go to 46 else go to 77
46 n27 Decision node, if true go to 47 else go to 51
47,48,49,50 n28 Sequential nodes
51 n29 Decision node, if true go to 52 else go to 68
52 n30 Intermediate node with one input edge & one output ege
53 n31 Decision node, if true go to 54 else go to 59
54 n32 Intermediate node
55 n33 Decision node, if true go to 56 else go to 58
56,57 n34 Sequential nodes
58 n35 Two edge from node 57 and 55 are terminated here
59 n36 Decision node, if true go to 60 else go to 63. Two edge from nodes 58 and
53 are terminated.
Cont….
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 114
Software Testing
Flow graph DD Path graph Remarks
nodes corresponding
node
60,61,62 n37 Sequential nodes
63,64,65,66 n38 Sequential nodes
67 n39 Two edge from node 62 and 66 are terminated here
68 n40 Decision node, if true go to 69 else go to 72
69,70,71 n41 Sequential nodes
72,73,74,75 n42 Sequential nodes
76 n43 Four edges from nodes 50, 67, 71 and 75 are terminated here.
77,78,79 n44 Sequential nodes
80 n45 Two edges from nodes 76 & 79 are terminated here
81 n46 Intermediate node
82,83,84 n47 Sequential nodes
85 n48 Two edges from nodes 81 and 84 are terminated here
86,87 n49 Sequential nodes with exit node
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 115
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 116
Software Testing
Example 8.13
Consider the problem for the determination of the nature of roots of a quadratic
equation. Its input a triple of positive integers (say a,b,c) and value may be from
interval [0,100].
The program is given in fig. 19. The output may have one of the following words:
[Not a quadratic equation; real roots; Imaginary roots; Equal roots]
Draw the flow graph and DD path graph. Also find independent paths from the DD
Path graph.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 118
Software Testing
Cont….
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 119
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 121
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007
Cont…. 123
Software Testing
Example 8.14
Consider a program given in Fig.8.20 for the classification of a triangle. Its input is a
triple of positive integers (say a,b,c) from the interval [1,100]. The output may be
[Scalene, Isosceles, Equilateral, Not a triangle].
Draw the flow graph & DD Path graph. Also find the independent paths from the DD
Path graph.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 125
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 126
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 127
Software Testing
Solution :
Flow graph of
triangle problem is:
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 128
Software Testing
The mapping table for DD path graph is:
Flow graph DD Path graph Remarks
nodes corresponding
node
1 TO 9 A Sequential nodes
10 B Decision node
11 C Decision node
19 H Decision node
22 J Decision node
Cont….
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 129
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 130
Software Testing
DD Path graph is given in Fig. 20 (b)
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 131
Software Testing
Cyclomatic Complexity
Here e = 9, n = 6 and P =1
There will be five independent paths for the flow graph illustrated in Fig. 21.
Path 1 : acf
Path 2 : abef
Path 3 : adcf
Path 4 : a b e a c f or a b e a b e f
Path 5 : abebef
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 133
Software Testing
Several properties of cyclomatic complexity are stated below:
1. V(G) ≥1
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 134
Software Testing
The role of P in the complexity calculation V(G)=e-n+2P is required to be understood
correctly. We define a flow graph with unique entry and exit nodes, all nodes
reachable from the entry, and exit reachable from all nodes. This definition would
result in all flow graphs having only one connected component. One could, however,
imagine a main program M and two called subroutines A and B having a flow graph
shown in Fig. 22.
Fig. 22
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 135
Software Testing
V (M A B) = e − n + 2P
= 13-13+2*3
=6
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 136
Software Testing
k k
V (C) = e − n + 2 p = ∑ ei − ∑ ni + 2K
i=1 i=1
k k
= ∑ (ei − ni + 2) = ∑ V (Ci )
i=1 i=1
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 137
Software Testing
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 138
Software Testing
Example 8.15
Consider a flow graph given in Fig. 23 and calculate the cyclomatic
complexity by all three methods.
Fig. 23
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 139
Software Testing
Solution
Cyclomatic complexity can be calculated by any of the three methods.
1. V(G) = e – n + 2P
= 13 – 10 + 2 = 5
2. V(G) =π+1
= 4 + 1 =5
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 140
Software Testing
Example 8.16
Consider the previous date program with DD path graph given in Fig. 17.
Find cyclomatic complexity.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 141
Software Testing
Solution
(i) V(G) = e – n + 2P = 65 – 49 + 2 = 18
(ii) V(G) = π + 1 = 17 + 1 = 18
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 142
Software Testing
Example 8.17
Consider the quadratic equation problem given in example 8.13 with its DD
Path graph. Find the cyclomatic complexity:
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 143
Software Testing
Solution
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 144
Software Testing
Example 8.18
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 145
Software Testing
Solution
Number of edges (e) = 23
Number of nodes (n) =18
(i) V(G) = e – n + 2P = 23 – 18 + 2 = 7
(ii) V(G) = π + 1 = 6 + 1 = 7
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 146
Software Testing
Graph Matrices
A graph matrix is a square matrix with one row and one column for every node in the
graph. The size of the matrix (i.e., the number of rows and columns) is equal to the
number of nodes in the flow graph. Some examples of graphs and associated
matrices are shown in fig. 24.
The square matrix represent that there are two path ab and cd from node 1 to
node 2.
Software Engineering (3rd ed.), By K.K Aggarwal & Yogesh Singh, Copyright © New Age International Publishers, 2007 151