Foundations of Software Testing
Foundations of Software Testing
Part I
Chapter 1 Chapter 2
Part II
Part III
Chapter 7 Chapter 8
Part IV
ADITYA P. MATHUR
Contents
Author: Aditya P. Mathur
Chapter 1:
Contents
Author: Aditya P. Mathur
Learning Objectives
Errors, Testing, debugging, test process, CFG, correctness, reliability,
oracles.
Testing techniques
Contents
Foundations of Software Testing 2E
Contents
Foundations of Software Testing 2E
Errors
Errors are a part of our daily life.
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
Humans make errors in their thoughts, actions, and in the products that
might result from their
actions.
Errors occur wherever humans are involved in taking actions and making
decisions.
Errors: Examples
Contents
Foundations of Software Testing 2E
Contents
Foundations of Software Testing 2E
Contents
Foundations of Software Testing 2E
Software quality
Contents
Foundations of Software Testing 2E
Contents
Foundations of Software Testing 2E
10
area in itself and there exist techniques for usability testing. Psychology plays
an important role in the design of techniques for usability testing.
Contents
Foundations of Software Testing 2E
11
Contents
Foundations of Software Testing 2E
12
Contents
Foundations of Software Testing 2E
13
Requirements: Incompleteness
of max when the input integers are 13 and 19 can be easily determined to be 19.
Suppose now that the tester wants to know if the two integers are to be input to the
program on one line followed by a carriage return, or on two separate lines with a
carriage return typed in after each number. The requirement as stated above fails to
provide an answer to this question.
Contents
Foundations of Software Testing 2E
14
Suppose that program max is developed to satisfy Requirement 1. The expected output
Contents
Foundations of Software Testing 2E
15
Requirements: Ambiguity
The set of all possible inputs to a program P is known as the input domain or input
space, of P.
Using Requirement 1 above we find the input domain of max
to be the set of all pairs of integers where each element in the pair integers is in the
range -32,768 till 32,767.
Using Requirement 2 it is not possible to find the input domain for the sort
program.
Contents
Foundations of Software Testing 2E
16
Contents
Foundations of Software Testing 2E
17
Based on the above modified requirement, the input domain for sort is a set of
pairs. The first element of the pair is a character. The second element of the pair
is a sequence of zero or more integers ending with a period.
Contents
Foundations of Software Testing 2E
18
Valid/Invalid Inputs
The modified requirement for sort mentions that the
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
request characters can be ``A'' and ``D'', but fails to answer the question ``What
if the user types a different character ?
When using sort it is certainly possible for the user to type a
character other than ``A'' and ``D''. Any character other than ``A' and ``D'' is
considered as invalid input to sort. The requirement for sort does not specify
what action it should take when an invalid input is encountered.
Contents
Foundations of Software Testing 2E
19
Contents
Foundations of Software Testing 2E
20
Correctness
21
While correctness attempts to establish that the program is error free, testing
attempts to find if there are any errors in it.
Thus, completeness of testing does not necessarily demonstrate that a program is
error free.
Testing, debugging, and the error removal processes together increase our
confidence in the correct functioning of the program under test.
Contents
Foundations of Software Testing 2E
22
Contents
Foundations of Software Testing 2E
23
Operational profile
Consider a sort program which, on any given execution, allows any one of two
types of input sequences. Sample operational profiles for sort follow.
Contents
Foundations of Software Testing 2E
24
Operational profile
Contents
Foundations of Software Testing 2E
25
Operational profile
Contents
Foundations of Software Testing 2E
26
Contents
Foundations of Software Testing 2E
27
Contents
Foundations of Software Testing 2E
28
A test/debug cycle
Contents
Foundations of Software Testing 2E
29
Test plan
Example: The sort program is to be tested to meet the requirements given earlier.
Specifically, the following needs to be done.
Execute sort on at least two input sequences, one with ``A'' and
the other with ``D'' as request characters.
Contents
Foundations of Software Testing 2E
30
Test the program for robustness against erroneous inputs such as ``R''
All failures of the test program should be recorded in a suitable file using
the Company Failure Report Form.
Contents
Foundations of Software Testing 2E
31
Test case/data
A test case is a pair consisting of test data to be input to the program and the
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
expected output. The test data is a set of values, one for each input variable.
Contents
Foundations of Software Testing 2E
32
Program behavior
A state diagram specifies program states and how the program changes its
state on an input sequence. inputs.
Contents
Foundations of Software Testing 2E
33
Consider a menu
driven application.
Contents
Foundations of Software Testing 2E
34
Contents
Foundations of Software Testing 2E
35
The entity that performs the task of checking the correctness of the
observed behavior is known as an oracle.
Contents
Foundations of Software Testing 2E
36
Oracle: Example
Contents
Foundations of Software Testing 2E
37
Oracle: Programs
Contents
Foundations of Software Testing 2E
38
Oracle: Construction
Contents
Foundations of Software Testing 2E
39
Contents
Foundations of Software Testing 2E
40
Contents
Foundations of Software Testing 2E
41
42
Contents
Foundations of Software Testing 2E
43
Test generation
Any form of test generation uses a source document. In the most informal of
test methods, the source document resides in the mind of the tester who
generates tests based on a knowledge of the requirements.
In several commercial environments, the process is a bit more formal. The tests are
generated using a mix of formal and informal methods either directly from the
requirements document serving as the source. In more advanced test processes,
requirements serve as a source for the development of formal models.
Contents
Foundations of Software Testing 2E
44
Contents
Foundations of Software Testing 2E
45
Contents
Foundations of Software Testing 2E
46
Contents
Foundations of Software Testing 2E
47
Types of testing
Contents
Foundations of Software Testing 2E
48
Contents
Foundations of Software Testing 2E
49
Contents
Foundations of Software Testing 2E
50
Contents
Foundations of Software Testing 2E
51
Contents
Foundations of Software Testing 2E
52
Summary
Contents
Foundations of Software Testing 2E
53
Chapter 2:
Preliminaries: Mathematical
Contents
Author: Aditya P. Mathur
54
Contents
Foundations of Software Testing 2E
55
Contents
Foundations of Software Testing 2E
56
The boiler is to be shut down when a or b is true or the boiler is in degraded mode
and the steam meter fails. We combine these five conditions to form a compound
condition (predicate) for boiler shutdown.
Contents
Foundations of Software Testing 2E
57
Denoting the five conditions above as a through e, we obtain the following Boolean
expression E that when true must force a boiler shutdown:
E=a+b+(c+d)e
where the + sign indicates OR and a multiplication indicates AND.
58
Another example
Contents
Foundations of Software Testing 2E
59
We will now examine two techniques, named BOR and BRO for generating tests
that are guaranteed to detect certain faults in the coding of conditions. The
conditions from which tests are generated might arise from requirements or might be
embedded in the program to be tested.
Contents
Foundations of Software Testing 2E
60
Predicates
Relational operators (relop):
{<, , >, , =, .}
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
61
(a b)
We also write ab for ab and a+b for ab when there is no confusion.
Singular Boolean expression: When each literal appears
only once, e.g., in (ab!c)
Contents
Foundations of Software Testing 2E
62
Boolean expressions
Contents
Foundations of Software Testing 2E
63
Mutually singular: Boolean expressions e1 and e2 are mutually singular when they
do not share any literal.
If expression E contains components e1, e2,.. then ei is considered singular only if it
is non-singular and mutually singular with the remaining elements of E.
Contents
Foundations of Software Testing 2E
64
<
(a+b)
!
c
Leaf nodes
Contents
Foundations of Software Testing 2E
65
Contents
Foundations of Software Testing 2E
66
Contents
Foundations of Software Testing 2E
67
Contents
Foundations of Software Testing 2E
68
Basic blocks
Contents
Foundations of Software Testing 2E
69
A control flow graph (or flow graph) G is defined as a finite set N of nodes and a finite
set E of edges. An edge (i, j) in E connects two nodes ni and nj in N. We often write G=
(N, E) to denote a flow graph G with nodes given by N and edges by E.
Contents
Foundations of Software Testing 2E
70
Contents
Foundations of Software Testing 2E
71
In a flow graph of a program, each basic block becomes a node and edges are used to
CFG Example
N={Start, 1, 2, 3, 4, 5, 6, 7, 8, 9, End}
E={(Start,1), (1, 2), (1, 3), (2,4), (3, 4), (4, 5), (5,
6), (6, 5), (5, 7), (7, 8), (7, 9), (9, End)}
Contents
Foundations of Software Testing 2E
72
CFG Example
N={Start, 1, 2, 3, 4, 5, 6, 7, 8, 9, End}
E={(Start,1), (1, 2), (1, 3), (2,4), (3, 4), (4, 5),
(5, 6), (6, 5), (5, 7), (7, 8), (7, 9), (9, End)}
Contents
Foundations of Software Testing 2E
73
Paths
Consider a flow graph G= (N, E). A sequence of k edges, k>0, (e_1, e_2, e_k) ,
denotes a path of length k through the flow graph if the following sequence
condition holds.
Given that np, nq, nr, and ns are nodes belonging to N, and 0< i<k, if ei =
(np, nq) and ei+1 = (nr, ns) then nq = nr. }
Contents
Foundations of Software Testing 2E
74
75
Paths: infeasible
Contents
Foundations of Software Testing 2E
76
Number of paths
condition contains exactly one path that begins at node Start and terminates at
node End.
Each additional condition in the program can increases the number of distinct paths
by at least one.
Depending on their location, conditions can have a multiplicative effect
on the number of paths.
Contents
Foundations of Software Testing 2E
77
Contents
Foundations of Software Testing 2E
78
Contents
Foundations of Software Testing 2E
79
Strings
Alphabet
Though alphabets can be infinite, we are concerned only with finite alphabets. For
example, X={0, 1} is an alphabet consisting of two symbols 0 and 1. Another
alphabet is Y={dog, cat, horse, lion}that consists of four symbols ``dog", ``cat",
``horse", and ``lion".
Contents
Foundations of Software Testing 2E
80
A string over an alphabet X is any sequence of zero or more symbols that belong to
X. For example, 0110 is a string over the alphabet {0, 1}. Also, dog cat dog dog lion
is a string over the alphabet {dog, cat, horse, lion}.
We will use lower case letters such as p, q, r to denote strings. The length of a string
is the number of symbols in that string. Given a string s, we denote its length by |s|.
Thus, |1011|=4 and |dog cat dog|=3. A string of length 0, also known as an empty
string, is denoted by .
Note that denotes an empty string and also stands for element of
Contents
Author: Aditya P. Mathur
81
Let s1 and s2 be two strings over alphabet X. We write s1.s2 to denote the
concatenation of strings s1 and s2.
For example, given the alphabet X={0, 1}, and two strings 011 and 101 over X, we
obtain 011.101=011101. It is easy to see that |s1.s2|=|s1|+|s2|. Also, for any string s, we
have s. =s and .s=s.
Contents
Foundations of Software Testing 2E
82
String concatenation
Languages
Contents
Foundations of Software Testing 2E
83
Let r1 and r2 be two regular expressions over the alphabet X that denote, respectively,
sets L1 and L2. Then r1.r2 is a regular expression that denotes the set L1.L2.
Contents
Foundations of Software Testing 2E
84
Regular expressions
If r is a regular expression that denotes the set L then r+ is a regular expression that
denotes the set obtained by concatenating L with itself one or more times also
written as L+ Also, r* known as the Kleene closure of r, is a regular expression. If r
denotes the set L then r* denotes the set {} L+.
If r1 and r2 are regular expressions that denote, respectively, sets L1 and L2, then r1r2 is
also a regular expression that denotes the set L1 L2.
Contents
Foundations of Software Testing 2E
85
Summary
Contents
Foundations of Software Testing 2E
86
Chapter 3
Domain Partitioning
Contents
Author: Aditya P. Mathur
87
Learning Objectives
Contents
Foundations of Software Testing 2E
88
Contents
Foundations of Software Testing 2E
89
Requirements
Test Plan
Model
Test Design
Test Case
Spec.
Spec.
Test Procedure
Test incident
Test log
report
report
Test summary
Test generation techniques
report
Contents
90
Contents
Author: Aditya P. Mathur
91
Test procedure spec: Describe the procedure for executing a test case.
Test transmittal report: Identifies the test items being provided for testing,
e.g. a database.
Test log: A log observations during the execution of a test.
Test incident report: Document any special event that is recommended for
further investigation.
Test summary: Summarize the results of testing activities and provide an
evaluation.
Contents
Foundations of Software Testing 2E
92
Contents
Foundations of Software Testing 2E
93
Contents
Foundations of Software Testing 2E
94
Requirements serve as the starting point for the generation of tests. During the initial
phases of development, requirements may exist only in the minds of one or more
people.
These requirements, more aptly ideas, are then specified rigorously using
modeling elements such as use cases, sequence diagrams, and statecharts in UML.
Rigorously specified requirements are often transformed into formal requirements
using requirements specification languages such as Z, S, and RSML.
Contents
Foundations of Software Testing 2E
95
Contents
Foundations of Software Testing 2E
96
Let D denote the input domain of a program P. The test selection problem is to
select a subset T of tests such that execution of P against each element of T will
reveal all errors in P.
In general there does not exist any algorithm to construct such a test set.
However, there are heuristics and model based methods that can be used to
generate tests that will reveal certain type of faults.
Contents
Foundations of Software Testing 2E
97
The challenge is to construct a test set TD that will reveal as many errors in P
as possible. The problem of test selection is difficult due primarily to the size
and complexity of the input domain of P.
Contents
Foundations of Software Testing 2E
98
Exhaustive testing
The large size of the input domain prevents a tester from exhaustively testing the
program under test against all possible inputs. By ``exhaustive" testing we mean
testing the given program against every element in its input domain.
Contents
Foundations of Software Testing 2E
99
If there is no limit on the size of the sequence that can be input, then the input domain
of P is infinitely large and P can never be tested exhaustively. If the size of the input
sequence is limited to, say Nmax>1, then the size of the input domain depends on the
value of N.
100
Contents
101
Contents
Contents
Foundations of Software Testing 2E
102
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.
Contents
Foundations of Software Testing 2E
103
Subdomains
Contents
Foundations of Software Testing 2E
104
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.
Contents
Foundations of Software Testing 2E
105
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).
Contents
Foundations of Software Testing 2E
106
Faults targeted
Contents
Foundations of Software Testing 2E
107
Example 1
the only legal values of age are in the range [1..120]. The set of input values is now divided
into a set E containing all integers in the range [1..120] and a set U containing the
remaining integers.
All integers
Other integers
[1..120]
Contents
Foundations of Software Testing 2E
108
Consider an application A that takes an integer denoted by age as input. Let us suppose that
Further, assume that the application is required to process all values in the range [1..61] in
accordance with requirement R1 and those in the range [62..120] according to requirement
R2.
Thus, E is further subdivided into two regions depending on the expected behavior.
Similarly, it is expected that all invalid inputs less than or equal to 1 are to be treated in one
way while all greater than 120 are to be treated differently. This leads to a subdivision of U
into two categories.
Contents
Foundations of Software Testing 2E
109
Example 1 (contd.)
All integers
<1
[62-120]
Example 1 (contd.)
>120
[1..61]
Contents
Foundations of Software Testing 2E
110
Tests selected using the equivalence partitioning technique aim at targeting faults in the
application under test with respect to inputs in any of the four regions, i.e., two regions
containing expected inputs and two regions containing the unexpected inputs.
It is expected that any single test selected from the range [1..61] will reveal any fault
with respect to R1. Similarly, any test selected from the region [62..120] will reveal
any fault with respect to R2. A similar expectation applies to the two regions
containing the unexpected inputs.
Contents
Foundations of Software Testing 2E
111
Example 1 (contd.)
The effectiveness of tests generated using equivalence partitioning for testing application
A, is judged by the ratio of the number of faults these tests are able to expose to the total
faults lurking in A.
As is the case with any test selection technique in software testing, the effectiveness of
tests selected using equivalence partitioning is less than 1 for most practical applications.
The effectiveness can be improved through an unambiguous and complete specification of
the requirements and carefully selected tests using the equivalence partitioning technique
described in the following sections.
Contents
Foundations of Software Testing 2E
112
Effectiveness
Example 2
This example shows a few ways to define equivalence classes based on the knowledge
of requirements and the program text.
Consider that wordCount method takes a word w and a filename f as input and
returns the number of occurrences of w in the text contained in the file named f. An
exception is raised if there is no file with name f.
Contents
Foundations of Software Testing 2E
113
Example 2 (contd.)
String w, f
Input w, f
if (not exists(f) {raise exception; return(0);}
if(length(w)==0)return(0);
if(empty(f))return(0);
return(getCount(w,f));
end
114
begin
Example 2 (contd.)
E1
non-null
E2
non-null
E3
non-null
exists, empty
E4
null
E5
null
E6
null
exists, empty
Equivalence class
Contents
Foundations of Software Testing 2E
115
Example 2 (contd.)
116
These two questions lead to two the following equivalence classes based on
outputs:
Contents
Foundations of Software Testing 2E
117
Based on the output equivalence classes one may now derive equivalence classes
for the inputs. Thus, each of the four classes given above might lead to one
equivalence class consisting of inputs.
Contents
Foundations of Software Testing 2E
118
Classes
Eq. Classes
area: float
area0.0
{{-1.0},
{15.52}}
age: int
{{-1}, {56},
{132}}
letter:bool
{{J}, {3}}
Contents
119
Equivalence Classes
At least one containing all
legal strings and one all
Example
Constraints
Classes
firstname: string {{}, {Sue},
{Loooong Name}}
Contents
Foundations of Software Testing 2E
120
Equivalence Classes
Constraints
Each value in a separate
class
autocolor:{red,
blue, green}
{{red,} {blue},
{green}}
up:boolean
{{true}, {false}}
Contents
Foundations of Software Testing 2E
121
Equivalence Classes
Constraints
One class containing all
legal arrays, one
Example
Classes
Contents
Foundations of Software Testing 2E
122
Contents
Foundations of Software Testing 2E
123
struct transcript
{
string fName; // First name.
string lName; // Last name.
string cTitle [200]; // Course titles.
char grades [200]; // Letter grades corresponding
to course titles.
}
In-class exercise: Derive equivalence classes for each component of R and
combine them!
Contents
Foundations of Software Testing 2E
124
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 uni-dimensional equivalence partitioning or simply uni-dimensional
partitioning.
Contents
Foundations of Software Testing 2E
125
uni-dimensional partitioning
Multidimensional partitioning
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.
126
Another way is to consider the input domain I as the set product of the input
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 x7 and 5y9.
Contents
Foundations of Software Testing 2E
127
E1: x<3
E2: 3x7
E3: x>7
E4: y<5
E5: 5y9
E6: y>9
y ignored.
x ignored.
128
Contents
Foundations of Software Testing 2E
129
6 equivalence classes:
E1: x<3, y<5
E3: x<3, y>9
E2: x<3, 5y9
E4: 3x7, y<5
E5: 3x7, 5y9
E6: 3x7, y>9
E7: >7, y<5
E8: x>7, 5y9
E9: x>7, y>9
9 equivalence classes:
Contents
130
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.
Contents
Foundations of Software Testing 2E
131
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.
Contents
Foundations of Software Testing 2E
132
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.
Contents
Foundations of Software Testing 2E
133
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.
Contents
Foundations of Software Testing 2E
134
of the options, C (for control), is used by a human operator to give one of four
commands (cmd): change the boiler temperature (temp), shut down the boiler (shut),
and cancel the request (cancel).
Command temp causes CS to ask the operator to enter the amount by which the
temperature is to be changed (tempch).
Values of tempch are in the range -10..10 in increments of 5 degrees Fahrenheit. An
temperature change of 0 is not an option.
Foundations of Software Testing 2E
Contents
135
The control software of BCS, abbreviated as CS, is required to offer several options. One
Selection of option C forces the BCS to examine variable V. If V is set to GUI, the
operator is asked to enter one of the three commands via a GUI. However, if V is set to
file, BCS obtains the command from a command file.
The command file may contain any one of the three commands, together with the value of
the temperature to be changed if the command is temp. The file name is obtained from
variable F.
Contents
Foundations of Software Testing 2E
136
V F
cmd: command
V, F: Environment variables
GUI
cmd
Control Software
(CS)
tempch: desired
temperature change
(-10..10)
datafile
V {GUI, file}
F: file name if V is set to file.
Contents
137
Contents
Foundations of Software Testing 2E
138
We assume that the control software is to be tested in a simulated environment. The tester
takes on the role of an operator and interacts with the CS via a GUI.
The GUI forces the tester to select from a limited set of values as specified in the
requirements. For example, the only options available for the value of tempch are -10, -5,
5, and 10. We refer to these four values of tempch as tvalid while all other values as
tinvalid.
Contents
Foundations of Software Testing 2E
139
The first step in generating equivalence partitions is to identify the (approximate) input
domain. Recall that the domain identified in this step will likely be a superset of the
complete input domain of the control software.
First we examine the requirements, identify input variables, their types, and values.
These are listed in the following table.
Contents
Foundations of Software Testing 2E
140
Variable
Kind
Type
Value(s)
Environment
Enumerated
File, GUI
Environment
String
A file name
cmd
Enumerated
tempch
Enumerated
Contents
Foundations of Software Testing 2E
141
Input domainS=VFcmdtempch
Sample values in the input domain (--: dont care):
(GUI, --, shut, --), (file, cmdfile, shut, --)
Contents
Foundations of Software Testing 2E
142
Variable
Partition
{{fvalid}, {finvalid}}
cmd
tempch
{{tvalid}, {tinvalid}}
Contents
Foundations of Software Testing 2E
143
Note that tinvalid, tvalid, finvalid, and fvalid denote sets of values. undefined
denotes one value.
There are a total of 3425=120 equivalence classes.
Sample equivalence class: {(GUI, fvalid, temp, -10)}
Note that each of the classes listed above represents an infinite number of input values
for the control software. For example, {(GUI}}, fvalid, temp, -10)} denotes an infinite set
of values obtained by replacing fvalid by a string that corresponds to the name of an
existing file. Each value is a potential input to the BCS.
Contents
Foundations of Software Testing 2E
144
Note that the GUI requests for the amount by which the boiler temperature is to be
changed only when the operator selects temp for cmd. Thus, all equivalence classes that
match the following template are infeasible.
{(V, F, {cancel, shut, cinvalid}, tvalid tinvalid)}
This parent-child relationship between cmd and tempch renders infeasible a total
of 3235=90 equivalence classes.
Exercise: How many additional equivalence classes are infeasible?
Contents
Foundations of Software Testing 2E
145
After having discarded all infeasible equivalence classes, we are left with a total of 18
testable (or feasible) equivalence classes.
Contents
Foundations of Software Testing 2E
146
Given a set of equivalence classes that form a partition of the input domain, it is
relatively straightforward to select tests. However, complications could arise in the
presence of infeasible data and don't care values.
In the most general case, a tester simply selects one test that serves as a
representative of each equivalence class.
Exercise: Generate sample tests for BCS from the remaining
feasible equivalence classes.
Contents
Foundations of Software Testing 2E
147
While designing equivalence classes for programs that obtain input exclusively from a
keyboard, one must account for the possibility of errors in data entry. For example, the
requirement for an application.
The application places a constraint on an input variable X such that it can assume
integral values in the range 0..4. However, testing must account for the possibility
that a user may inadvertently enter a value for X that is out of range.
Contents
Foundations of Software Testing 2E
148
Suppose that all data entry to the application is via a GUI front end. Suppose also that the
GUI offers exactly five correct choices to the user for X.
In such a situation it is impossible to test the application with a value of X that is out of
range. Hence only the correct values of X will be input. See figure on the next slide.
Contents
Foundations of Software Testing 2E
149
Contents
Foundations of Software Testing 2E
150
Contents
Foundations of Software Testing 2E
151
Contents
Author: Aditya P. Mathur
152
Experience indicates that programmers make mistakes in processing values at and near the
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.
Contents
Foundations of Software Testing 2E
153
BVA: Procedure
Partition the input domain using uni-dimensional 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.
Select test data such that each boundary value occurs in at least one test input.
Contents
Foundations of Software Testing 2E
154
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.
Contents
Foundations of Software Testing 2E
155
* x
99
E1
100
998
*
E2
0
*
E4
x
1
99
*
E5
1000
x *
999 E3
98
101
x *
100 E6
Contents
156
qty included.
157
must include, for each variable, values at and around the boundary. Consider the
Is there an advantage of separating the invalid values of code and age into different
test cases?
158
Is T the best possible test set for findPrice? Answer this question based on Ts
BVA: Recommendations
Contents
Foundations of Software Testing 2E
159
Contents
Foundations of Software Testing 2E
160
Contents
Foundations of Software Testing 2E
161
The boiler is to be shut down when a or b is true or the boiler is in degraded mode
and the steam meter fails. We combine these five conditions to form a compound
condition (predicate) for boiler shutdown.
Contents
Foundations of Software Testing 2E
162
Denoting the five conditions above as a through e, we obtain the following Boolean
expression E that when true must force a boiler shutdown:
E=a+b+(c+d)e
where the + sign indicates OR and a multiplication indicates AND.
163
Another example
Contents
Foundations of Software Testing 2E
164
Summary
Equivalence partitioning and boundary value analysis are the most commonly
used methods for test generation while doing functional testing.
Given a function f to be tested in an application, one can apply these
techniques to generate tests for f.
Contents
Foundations of Software Testing 2E
165
Chapter 4
Predicate Analysis
Contents
Author: Aditya P. Mathur
166
Domain testing
Cause-effect graphing
Learning Objectives
Contents
Foundations of Software Testing 2E
167
Contents
Foundations of Software Testing 2E
168
Contents
Foundations of Software Testing 2E
169
(a<b) (c>d) e
(a<b) ! (c>d) e
(a<b) (c>d) e
(a<b) (e>d) c
Contents
Foundations of Software Testing 2E
170
(a==b) (c>d) e
(a==b) (cd) e
(a==b) (c>d) e
Contents
Foundations of Software Testing 2E
171
Correct predicate: Ec: e1 relop1 e2. Incorrect predicate: Ei: : e3 relop2 e4. Assume
that Ec and Ei use the same set of variables.
Ei has an off-by- fault if |e3-e4|= for any test case for which e1=e2.
Ei has an off-by-* fault if |e3-e4| for any test case for which e1=e2.
Ei has an off-by-+ fault if |e3-e4|> for any test case for which e1=e2.
Contents
Foundations of Software Testing 2E
172
Ei: a<b. Given c=1, Ei has an off-by-1 fault as |a-b|= 1 for a test case for which
a=b+c, e.g. <a=2, b=1, c=1>.
Ei: a<b+1. Given c=2, Ei has an off-by-1* fault as |a-(b+1)| 1 for any test case
for which a=b+c; <a=4, b=2, c=2>
Ei: a<b-1. Given c>0, Ei has an off-by-1+ fault as |a-(b-1)|>1 for any test case for
which a=b+c; <a=3, b=2, c=1>.
Contents
Foundations of Software Testing 2E
173
174
Given a correct predicate pc, the goal of predicate testing is to generate a test set T
such that there is at least one test case t T for which pc and its faulty version pi,
evaluate to different truth values.
Such a test set is said to guarantee the detection of any fault of the kind in the
fault model introduced above.
Contents
Foundations of Software Testing 2E
175
As an example, suppose that pc: a<b+c and pi: a>b+c. Consider a test set T={t1, t2}
where t1: <a=0, b=0, c=0> and t2: <a=0, b=1, c=1>.
176
Correct predicate: a b
Missing Boolean variable fault: a
Extra Boolean variable fault: a bc
Contents
Foundations of Software Testing 2E
177
Contents
Foundations of Software Testing 2E
178
For example, consider the predicate E: a<b and the constraint > . A test case
that satisfies this constraint for E must cause E to evaluate to false.
Contents
Foundations of Software Testing 2E
179
Contents
Foundations of Software Testing 2E
180
Infeasible constraints
Predicate constraints
Test case t satisfies C for predicate pr, if each component of pr satisfies the
corresponding constraint in C when evaluated against t. Constraint C for predicate
pr guides the development of a test for pr, i.e., it offers hints on what the values of
the variables should be for pr to satisfy C.
Contents
Foundations of Software Testing 2E
181
pr(C) denotes the value of predicate pr evaluated using a test case that satisfies C.
C is referred to as a true constraint when pr(C) is true and a false constraint
otherwise.
A set of constraints S is partitioned into subsets St and Sf, respectively, such that for
each C in St, pr(C) =true, and for any C in Sf, pr(C) =false. S= St Sf.
Contents
Foundations of Software Testing 2E
182
Consider the predicate pr: b (r<s) (uv) and a constraint C: (t, =, >). The
following test case satisfies C for pr.
<b=true, r=1, s=1, u=1, v=0>
The following test case does not satisfy C for pr.
<b=true, r=1, s=2, u=1, v=2>
Contents
Foundations of Software Testing 2E
183
Contents
Foundations of Software Testing 2E
184
T is minimal and
T guarantees the detection of any fault in the implementation of pr; faults correspond
to the fault model we discussed earlier.
We will discuss three such criteria named BOR, BRO, and BRE.
Contents
Foundations of Software Testing 2E
185
A test set T that satisfies the BOR testing criterion for a compound predicate pr,
guarantees the detection of single or multiple Boolean operator faults in the
implementation of pr.
T is referred to as a BOR-adequate test set and sometimes written as TBOR.
Contents
Foundations of Software Testing 2E
186
A test set T that satisfies the BRO testing criterion for a compound predicate pr,
guarantees the detection of single Boolean operator and relational operator faults in
the implementation of pr.
T is referred to as a BRO-adequate test set and sometimes written as TBRO.
Contents
Foundations of Software Testing 2E
187
A test set T that satisfies the BRE testing criterion for a compound predicate pr,
guarantees the detection of single Boolean operator, relational expression, and
arithmetic expression faults in the implementation of pr.
T is referred to as a BRE-adequate test set and sometimes written as TBRE.
Contents
Foundations of Software Testing 2E
188
Let Tx, x{BOR, BRO,BRE}, be a test set derived from predicate pr. Let pf be
another predicate obtained from pr by injecting single or multiple faults of one of
three kinds: Boolean operator fault, relational operator fault, and arithmetic
expression fault.
Contents
Foundations of Software Testing 2E
189
Contents
Foundations of Software Testing 2E
190
Contents
Foundations of Software Testing 2E
191
Contents
Foundations of Software Testing 2E
192
193
Contents
Foundations of Software Testing 2E
194
a<b
c>d
Contents
195
Given node N in the syntax tree for predicate pr, we use the following notation:
SN= SNt SNf is the constraint set, where
SNt is the true constraint set, and
SNf is the false constraint.
Contents
Foundations of Software Testing 2E
196
Second, label each leaf node with the constraint set {(t), (f)}.
We label the nodes as N1, N2, and so on for convenience.
N3
N1
SN1=
c>d
a<b
{(t), (f)}
SN2=
N2
{(t), (f)}
197
case N3. For an AND node, the formulae used are the following.
SN3={(t,t), (f, t), (t, f)}
SN3t = SN1t SN2t ={(t)}
{(t)}={(t, t)}
N2
N1
c>d
{(t), (f)}
a<b
N3
{(t), (f)}
198
Third, compute the constraint set for the next higher node in the syntax tree, in this
Generation of TBOR
the AST(pr). We can now generate a test set using the BOR constraint set associated
with the root node.
SN3={(t,t), (f, t), (t, f)}
N3
N2
N1
c>d
{(t), (f)}
a<b
{(t), (f)}
199
As per our objective, we have computed the BOR constraint set for the root node of
Recall that a test set adequate with respect to a BRO constraint set for predicate pr,
guarantees the detection of all combinations of single or multiple Boolean operator
and relational operator faults.
Contents
Foundations of Software Testing 2E
200
Sf={(=), (<)}
Sf={(<)}
relop: = St={(=)}
Sf={(<), (>)}
Sf={(=), (>)}
Sf={(>)}
201
Contents
N4
r>s
N1
a+b<c
N6
N5
N3
N2
Contents
202
N4
N6
r>s
N1
a+b<c
{(>), (=), (<)}
N3
N5
N2
{(t), (f)}
Contents
Foundations of Software Testing 2E
203
StN3=SN2f={(f)}
Step 2: Traverse the tree and compute constraint set for each internal node.
SfN3=SN2t= {(t)}
204
{(<, f), (>, f), (=, f), (<, t)}
N4
r>s
N1
a+b<c
{(>), (=), (<)}
N6
N5
N3 {(f), {t)}
N2
{(t), (f)}
Contents
Foundations of Software Testing 2E
205
Next compute the constraint set for the rot node (this is an OR-node).
SfN6=SfN4 SfN5
={(>,f),(=,f),(<,t)} {(=),(<)}={(<, f)}
={(>,f,=), (=,f,<),(<,t,=)}
StN6=
(StN4 {(fN5)}) ({(fN4)} StN5)
=({(<,f)} {(=)}) {(>,f)} {(>)})
={(<,f,=)} {(>,f,>)}
={(<,f,=),(>,f,>)}
Contents
206
N6
N4
N1
a+b<c
{(>), (=), (<)}
r>s
N3 {(f), {t)}
!
p
N2
{(t), (f)}
Foundations of Software Testing 2E
N5
Contents
207
Given the constraint set for pr: (a+b<c)!p (r>s), construct TBRO .
{(>,f,=), (=,f,<),(<,t,=), (<,f,=),(>,f,>)}
Contents
Foundations of Software Testing 2E
208
Contents
Foundations of Software Testing 2E
209
Test generation procedures described so far are for singular predicates. Recall that a
singular predicate contains only one occurrence of each variable.
We will now learn how to generate BOR constraints for non-singular predicates.
Contents
Foundations of Software Testing 2E
210
Predicate (pr)
DNF
ab(b+c)
abb+abc
a; b(b+c)
a(bc+ bd)
abc+abd
a; (bc+bd)
a(!b+!c)+cde
a!ba +a!c+cde
a; !b+!c+ cde
a(bc+!b+de)
abc+a!b+ade
a; bc+!b; de
Contents
Foundations of Software Testing 2E
211
Contents
Foundations of Software Testing 2E
212
Contents
Foundations of Software Testing 2E
213
MI procedure: An Example
Recall that + is the Boolean OR operator, ! is the Boolean NOT operator, and as
per common convention we have omitted the Boolean AND operator. For example
bc is the same as bc.
Contents
Foundations of Software Testing 2E
214
Step 0: Express E in DNF notation. Clearly, we can write E=e1+e2, where e1=abc
and e2=a!bd.
Step 1: Construct a constraint set Te1 for e1 that makes e1 true. Similarly construct
Te2 for e2 that makes e2 true.
Te1 ={(t,t,t,t), (t,t,t,f)}
Note that the four ts in the first element of Te1 denote the values of the Boolean
variables a, b,c, and d, respectively. The second element, and others, are to be
interpreted similarly.
Contents
Foundations of Software Testing 2E
215
Step 2: From each Tei , remove the constraints that are in any other Tej. This gives
us TSei and TSej. Note that this step will lead TSei TSej =.
There are no common constraints between Te1 and Te2 in our example. Hence we
get:
TSe1 ={(t,t,t,t), (t,t,t,f)}
Contents
Foundations of Software Testing 2E
216
Note that for each constraint x in StE we get E(x)=true. Also, StE is minimal. Check
it out!
Contents
Foundations of Software Testing 2E
217
Step 4: For each term in E, obtain terms by complementing each literal, one at a
time.
e11= !abc
e21= a!bc
e31= ab!c
e12= !a!bd
From each term e above, derive constraints Fe that make e true. We get the
following six sets.
Contents
Foundations of Software Testing 2E
218
Contents
Foundations of Software Testing 2E
219
Step 5: Now construct FSe by removing from Fe any constraint that appeared in any
of the two sets Te constructed earlier.
FSe11= FSe11
FSe21= {(t,f,t,f)}
FSe31= FSe13
FSe12= FSe12
FSe22= {(t,t,f,t)}
FSe32= FSe13
Contents
Foundations of Software Testing 2E
220
221
Contents
Foundations of Software Testing 2E
222
BOR-MI-CSET procedure
BOR-MI-CSET: Example
We use the BOR-CSET procedure to generate the constraint set for e1 (singular
component) and MI-CSET procedure for e2 (non-singular component).
Contents
Foundations of Software Testing 2E
223
Recall that Ste1 is true constraint set for e1 and Sfe1 is false constraint set for e1.
Contents
Foundations of Software Testing 2E
224
Component e2 is a DNF expression. We can write e2=u+v where u=bc and v=!
bd.
Let us now apply the MI-CSET procedure to obtain the BOR constraint set for
e2.
As per Step 1 of the MI-CSET procedure we obtain:
Tu={(t,t,t), (t,t,f)} Tv={(f,t,t), (f,f,t)}
Contents
Foundations of Software Testing 2E
225
TSu=Tu TSv=Tv
Ste2={(t,t,f), (f, t, t)}
Next we apply Step 4 to u and v. We obtain the following complemented
expressions from u and v:
One possible alternative. Can
you think of other alternatives?
u1=!bc
u2=b!c
v1=bd
v2=!b!d
Contents
226
Fu1={(f,t,t), (f,t,f)}
Fu2=(t,f,t), (t,f,f)}
Fv1={(t,t,t), (t,f,t)}
Fv2={(f,t,f), (f,f,f)}
FSu1={(f,t,f)}
FSu2=(t,f,t), (t,f,f)}
227
Contents
Foundations of Software Testing 2E
228
Ste1={(t)}
Sfe1={(f)}
Summary:
from BOR-CSET
procedure.
Sfe2={(f,t,f), (t,f,t)}
from MI-CSET
procedure.
Contents
Foundations of Software Testing 2E
229
AND node.
N3
{(t,t,t,f), (t,f,t,t), (f,t,t,f),(t,f,t,f),(t,t,f,t)}
N2
{(t,t,f), (f, t, t), (f,t,f), (t,f,t)}
N1
a
{(t),(f)}
b
!b
Apply MI-CSET
Foundations of Software Testing 2E
Contents
230
Contents
Foundations of Software Testing 2E
231
Summary
Summary (contd.)
232
Chapter 5
Contents
Author: Aditya P. Mathur
233
Learning Objectives
UIO method is not covered in these slides. It is left for the students to read on
their own (Section 5.8).
Contents
Foundations of Software Testing 2E
234
Finite state machines are widely used in modeling of all kinds of systems.
Generation of tests from FSM specifications assists in testing the
conformance of implementations to the corresponding FSM model.
Alert: It will be a mistake to assume that the test generation methods described
here are applicable only to protocol testing!
Contents
235
Contents
Foundations of Software Testing 2E
236
Contents
Foundations of Software Testing 2E
237
Not all aspects of an applications requirements are specified by an FSM. Real time
requirements, performance requirements, and several types of computational
requirements cannot be specified by an FSM.
Contents
Foundations of Software Testing 2E
238
An FSM could serve any of two roles: as a specification of the required behavior and/
or as a design artifact according to which an application is to be implemented.
Contents
Foundations of Software Testing 2E
239
While the FSMs considered in examples are abstract machines, they are abstractions
of many real-life machines.
Contents
Foundations of Software Testing 2E
240
Note that FSMs are different from statecharts. While FSMs can be modeled using
statecharts, the reverse is not true.
Techniques for generating tests from FSMs are different from those for generating tests
from statecharts.
The term state diagram is often used to denote a graphical representation of an FSM
or a statechart.
Contents
Foundations of Software Testing 2E
241
242
Contents
Foundations of Software Testing 2E
243
Contents
Foundations of Software Testing 2E
244
Blue: Generated
Test driver
data
Pass/fail
Test inputs
Oracle
Requirements
FSM based
Test inputs
Application
Observed behavior
Contents
245
Embedded systems
automobile has several embedded computers to perform various tasks, engine control
being one example. Another example is a computer inside a toy for processing inputs
and generating audible and visual responses.
Such devices are also known as embedded systems. An embedded system can be as
simple as a child's musical keyboard or as complex as the flight controller in an aircraft.
In any case, an embedded system contains one or more computers for processing
inputs.
Contents
Foundations of Software Testing 2E
246
Contents
Foundations of Software Testing 2E
247
248
249
Contents
Foundations of Software Testing 2E
250
O: Q x X Y is an output function.
In some variants of FSM more than one state could be specified as an
initial state. Also, sometimes it is convenient to add F Q as a set of
final or accepting states while specifying an FSM.
Contents
Foundations of Software Testing 2E
251
A state diagram is a directed graph that contains nodes representing states and
edges representing state transitions and output functions.
Each node is labeled with the state it represents. Each directed edge in a state
diagram connects two states. Each edge is labeled i/o where i denotes an input
symbol that belongs to the input alphabet X and o denotes an output symbol that
belongs to the output alphabet O. i is also known as the input portion of the edge and
o its output portion.
Contents
Foundations of Software Testing 2E
252
Contents
Foundations of Software Testing 2E
253
The table consists of two sub-tables that consist of one or more columns each. The
leftmost sub table is the output or the action sub-table. The rows are labeled by the
states of the FSM. The rightmost sub-table is the next state sub-table.
Contents
Foundations of Software Testing 2E
254
The table given below shows how to represent functions and O for
the DIGDEC machine.
Contents
Foundations of Software Testing 2E
255
Contents
Foundations of Software Testing 2E
256
Contents
Foundations of Software Testing 2E
257
Properties of FSM
V-equivalence: Let M1=(X, Y, Q1, m10, T1, O1) and M2=(X, Y, Q2, m20, T2, O2) be
two FSMs. Let V denote a set of non-empty strings over the input alphabet X i.e.
V X+.
Let qi and qj, i j, be the states of machines M1 and M2, respectively. qi and qj are
considered V-equivalent if O1(qi, s)=O2(qj, s) for all s in V.
Contents
Foundations of Software Testing 2E
258
States qi and qj are said to be equivalent if O1(qi, r)=O2(qj, r) for any set V. If qi and
qj are not equivalent then they are said to be distinguishable. This definition of
equivalence also applies to states within a machine. Thus, machines M1 and M2
could be the same machine.
Contents
Foundations of Software Testing 2E
259
state in M1 there exists a state ' in M2 such that and ' are equivalent and (b)
for each state in M2 there exists a state ' in M1 such that and ' are
equivalent.
Machines that are not equivalent are considered distinguishable.
Minimal machine: An FSM M is considered minimal if the number of states in M
is less than or equal to any other FSM equivalent to M.
Contents
Foundations of Software Testing 2E
260
Machine equivalence: Machines M1 and M2 are said to be equivalent if (a) for each
k-equivalence: Let M1=(X, Y, Q1, m10, T1, O1) and M2=(X, Y, Q2, m20, T2, O2) be
two FSMs.
States qi Q1 and qj Q2 are considered k-equivalent if, when excited by any input
of length k, yield identical output sequences.
Contents
Foundations of Software Testing 2E
261
Once again, M1 and M2 may be the same machines implying that kdistinguishability applies to any pair of states of an FSM.
It is also easy to see that if two states are k-distinguishable for any k>0 then
they are also distinguishable for any n k. If M1 and M2 are not kdistinguishable then they are said to be k-equivalent.
Contents
Foundations of Software Testing 2E
262
Contents
Foundations of Software Testing 2E
263
Contents
Foundations of Software Testing 2E
264
Contents
Foundations of Software Testing 2E
265
Faults in implementation
Fault model
a/0
q0
q0
a/1
b/1
q0
a/1
b/1
a/1
b/1
q1
q1
q1
b/0
b/0
b/0
Correct design
a/1
Operation error
a/1
Transfer error
Contents
266
a/1
b/1
a/0
q0
q0
a/1
q2
a/1
b/0
q1
b/0
Extra state error
267
Contents
Foundations of Software Testing 2E
268
Contents
Foundations of Software Testing 2E
269
Step 1: Estimate the maximum number of states (m) in the correct implementation
of the given FSM M.
Step 2: Construct the characterization set W for M.
Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P
from the testing tree.
Step 4: Construct set Z from W and m.
Step 5: Desired test set=P.Z
Contents
Foundations of Software Testing 2E
270
Step 1: Estimation of m
Contents
Foundations of Software Testing 2E
271
Contents
Foundations of Software Testing 2E
272
Example of a W-set
W={baaa,aa,aaa}
O(baaa,q1)=1101
O(baaa,q2)=1100
273
Contents
Foundations of Software Testing 2E
274
Contents
Foundations of Software Testing 2E
275
Output
Next state
q1
q1
q4
q2
q1
q5
q3
q5
q1
q4
q3
q4
q5
q2
q5
Contents
276
Group states identical in their Output entries. This gives us 1-partition P1 consisting
Current
state
Output
q1
q1
q4
q2
q1
q5
q3
q5
q1
q4
q3
q4
q5
q2
q5
Contents
277
Current
state
Next state
q1
q11
q42
q2
q11
q52
q3
q52
q11
q4
q31
q42
q5
q21
q52
P1 Table
Group number
Contents
Foundations of Software Testing 2E
278
Rewrite P1 table. Remove the output columns. Replace a state entry qi by qij where j
Current
state
Next state
q1
q11
q43
q2
q11
q53
q3
q53
q11
q4
q32
q43
q5
q21
q53
P2 Table
Contents
Foundations of Software Testing 2E
279
Group all entries with identical second subscripts under the next state column. This
Current
state
Next state
q1
q11
q43
q2
q11
q54
q3
q54
q11
q4
q32
q43
q5
q21
q54
P3 Table
Contents
Foundations of Software Testing 2E
280
Group all entries with identical second subscripts under the next state column. This
Current
state
P4 Table
Next state
q1
q11
q44
q2
q11
q55
q3
q55
q11
q4
q33
q44
q5
q22
q55
Contents
281
When the process converges, and the machine is minimal, each state will be in a
separate group.
The next step is to obtain the distinguishing strings for each state.
Contents
Foundations of Software Testing 2E
282
Find tables Pi and Pi+1 such that (q1, q2) are in the same group in Pi and different
groups in Pi+1. We get P3 and P4.
Initialize z=. Find the input symbol that distinguishes q1 and q2 in table P3. This
symbol is b. We update z to z.b. Hence z now becomes b.
Contents
Foundations of Software Testing 2E
283
We move to the P2 table and find the input symbol that distinguishes q4 and q5. Let
us select a as the distinguishing symbol. Update z which now becomes ba.
The next states for states q4 and q5 on symbol a are, respectively, q3 and q2.
These two states are distinguished in P1 by a and b. Let us select a. We update z to
baa.
Contents
Foundations of Software Testing 2E
284
We update z to baaa. This is the farthest we can go backwards through the various
tables. baaa is the desired distinguishing sequence for states q1 and q2. Check that
o(q1,baaa)o(q2,baaa).
Contents
Foundations of Software Testing 2E
285
Using the procedure analogous to the one used for q1 and q2, we can find the
distinguishing sequence for each pair of states. This leads us to the following
characterization set for our FSM.
Contents
Foundations of Software Testing 2E
286
Step 1: Estimate the maximum number of states (m) in the correct implementation
Done
of the given FSM M.
Step 2: Construct the characterization set W for M.
Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P
Next (a)
from the testing tree.
Step 4: Construct set Z from W and m.
Step 5: Desired test set=P.Z
Contents
Foundations of Software Testing 2E
287
path from the initial state to the remaining states in the FSM. Here is how we
construct the testing tree.
State q0, the initial state, is the root of the testing tree. Suppose that the testing tree has
been constructed until level k . The (k+1)th level is built as follows.
Select a node n at level k. If n appears at any level from 1 through k , then n is a leaf
node and is not expanded any further. If n is not a leaf node then we expand it by
adding a branch from node n to a new node m if (n, x)=m for x X . This branch
is labeled as x. This step is repeated for all nodes at level k.
Contents
Foundations of Software Testing 2E
288
A testing tree of an FSM is a tree rooted at the initial state. It contains at least one
q1 becomes leaf, q4
can be expanded.
M
.
.
No further expansion
possible
.
Contents
Foundations of Software Testing 2E
289
Step 1: Estimate the maximum number of states (m) in the correct implementation
Done
of the given FSM M.
Step 2: Construct the characterization set W for M.
Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P
Next, (b)
from the testing tree.
Step 4: Construct set Z from W and m.
Step 5: Desired test set=P.Z
Contents
Foundations of Software Testing 2E
290
Step 3: (b) Find the transition cover set from the testing tree
root, in the testing tree. Concatenation of the labels along the edges of a sub-path is
a string that belongs to P. The empty string () also belongs to P.
Contents
Foundations of Software Testing 2E
291
A transition cover set P is a set of all strings representing sub-paths, starting at the
Step 1: Estimate the maximum number of states (m) in the correct implementation
Done
Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P
Done
from the testing tree.
Step 4: Construct set Z from W and m.
Next
Contents
Foundations of Software Testing 2E
292
Given that X is the input alphabet and W the characterization set, we have:
Z = X0.W X1.W .. Xm-1-n.W Xm-n.W
For m=n, we get
Z = X0.W=W
For X={a, b}, W={a, aa, aaa, baaa}, m=6
Z = W X1.W ={a, aa, aaa, baaa} {a, b}.{a, aa, aaa, baaa}
={a, aa, aaa, baaa, aa, aaa, aaaa, baaaa, ba, baa, baaa,
bbaaa}
Contents
Foundations of Software Testing 2E
293
Step 1: Estimate the maximum number of states (m) in the correct implementation
Done
Step 3: (a) Construct the testing tree for M and (b) generate the transition cover set P
Done
from the testing tree.
Step 4: Construct set Z from W and m.
Step 5: Desired test set=P.Z
Done
Next
Contents
294
The test inputs based on the given FSM M can now be derived as:
T=P.Z
Do the following to test the implementation:
1. Find the expected response to each element of T.
2. Generate test cases for the application. Note that even though the application
is modeled by M, there might be variables to be set before it can be exercised
with elements of T.
3. Execute the application and check if the response matches. Reset the
application to the initial state after each test.
Foundations of Software Testing 2E
Contents
295
Error revealing
M(t1)=1101001
M(t2)=11011
test cases
Correct design
t1=baaaaaa
t2=baaba
M1(t1)=1101001
M2(t2)=11001
M1
Contents
M2
Author: Aditya P. Mathur
296
M1
M2
t1=baaba
M(t1)=11011
M1(t1)=11001
t2=baaa
M(t2)=1101
M2(t2)=1100
Contents
297
moves the application from initial state q0 to state qj. Then, s=as takes it
from qi to state qj or qj.
Contents
Foundations of Software Testing 2E
298
Contents
Foundations of Software Testing 2E
299
Size of tests generated is generally smaller than that generated using the W-method.
Test generation process is divided into two phases: Phase 1: Generate a test set using
the state cover set (S) and the characterization set (W). Phase 2: Generate additional
tests using a subset of the transition cover set and state identification sets.
300
strings over X* such that for each state qi in Q, there is a string in S that takes M from
its initial state to qi.
301
Given FSM M with input alphabet X, a state cover set S is a finite non-empty set of
Given an FSM M with Q as the set of states, an identification set for state qiQ is
denoted by Wi and has the following properties:
(a) Wi W , 1 in [Identification set is a subset of W.]
(b) O(qi, s) O(qj, s) , for 1j n , j i , s Wi [For each state other than qi, there is
a string in Wi that distinguishes qi from qj.]
(c) No subset of Wi satisfies property (b). [Wi is minimal.]
Contents
Foundations of Software Testing 2E
302
Si
Sj
o(Si,x)
o(Sj,x)
baaa
aa
aa
aaa
3
W1=W2={baaa, aa, a}
W3={a aa} W4=W5={a, aaa}
Foundations of Software Testing 2E
Contents
Author: Aditya P. Mathur
303
Contents
Foundations of Software Testing 2E
304
Contents
Foundations of Software Testing 2E
305
R=P-S={,
ba, baa, baaa}
={a, bb, bab, baab, baaab, baaaa}
Let each element of R be denoted as ri1, ri2,rik.
(rik, m)=qij , where mX (the alphabet)
Contents
Foundations of Software Testing 2E
306
(q1, a)=q1
(q1, bb)=q4
(q1, baab)=q5
T2=RW=k(j=1) (rij}. Wij , where Wij is the identification set for state qij.
(q1, bab)=q5
Contents
Foundations of Software Testing 2E
307
Test set size using the Wp method= 34 (20 from T1+14 from T2)
Contents
Foundations of Software Testing 2E
308
Tests from T1 are applied in phase 1. Tests from T2 are applied in phase 2.
While tests from phase 1 ensure state coverage, they do not ensure all transition
coverage. Also, even when tests from phase cover all transitions, they do not apply
the state identification sets and hence not all transfer errors are guaranteed to be
revealed by these tests.
Contents
Foundations of Software Testing 2E
309
Wp method:
Contents
Foundations of Software Testing 2E
310
Contents
Foundations of Software Testing 2E
311
Contents
Foundations of Software Testing 2E
312
The W and the Wp methods are considered automata-theoretic methods for test
generation.
In contrast, many books on software testing mention control-theoretic techniques
for test generation. Let us understand the difference between the two types of
techniques and their fault detection abilities.
Contents
Foundations of Software Testing 2E
313
State cover: A test set T is considered adequate with respect to the state cover
criterion for an FSM M if the execution of M against each element of T causes
each state in M to be visited at least once.
Transition cover: A test set T is considered adequate with respect to the branch/
transition cover criterion for an FSM M if the execution of M against each
element of T causes each transition in M to be taken at least once
Contents
Foundations of Software Testing 2E
314
Switch cover: A test set T is considered adequate with respect to the 1-switch
cover criterion for an FSM M if the execution of M against each element of T
causes each pair of transitions (tr1, tr2) in M to be taken at least once, where for
some input substring ab tr1: qi=(qj, a) and tr_2: qk= (qi, b) and qi, qj, qk
are states in M.
Contents
Foundations of Software Testing 2E
315
Boundary interior cover: A test set T is considered adequate with respect to the
boundary-interior cover criterion for an FSM M if the execution of M against each
element of T causes each loop (a self-transition) across states to be traversed zero times
and at least once. Exiting the loop upon arrival covers the ``boundary" condition and
entering it and traversing the loop at least once covers the ``interior" condition.
Contents
Foundations of Software Testing 2E
316
(M1).
t=abba covers all states but does not not
reveal the error. Both machines
generate the same output which is 0111.
Will the tests generated by the W
method reveal this error? Check it out!
Contents
Foundations of Software Testing 2E
317
Consider the following machines, a correct one (M1) and one with a transfer error
(M2).
There are 12 branch pairs, such as (tr1,
tr2), (tr1, tr3), tr6, tr5).
Consider the test set: {bb, baab, aabb,
aaba, abbaab}. Does it cover all
branches? Does it reveal the error?
318
Consider the following machines, a correct one (M2) and one with a transfer error
(M3).
Consider T={t1: aab, t2: abaab}. T1
causes each state to be entered but loop
Consider the following machines, a correct one (M3) and one with a transfer error
Contents
Foundations of Software Testing 2E
319
Summary
Contents
Foundations of Software Testing 2E
320
Summary (contd.)
Automata theoretic techniques generate tests superior in their fault detection ability
than their control-theoretic counterparts.
Control-theoretic techniques, that are often described in books on software testing,
include branch cover, state cover, boundary-interior, and n-switch cover.
The size of tests sets generated by the W method is larger than generated by the Wp
method while their fault detection effectiveness are the same.
Contents
Foundations of Software Testing 2E
321
Chapter 6
Contents
Author: Aditya P. Mathur
322
What are test configurations? How do they differ from test sets?
What are Latin squares and mutually orthogonal Latin squares (MOLS)?
Learning Objectives
Contents
Foundations of Software Testing 2E
323
Contents
Foundations of Software Testing 2E
324
Each environment corresponds to a given set of values for each factor, known
as a test configuration.
Contents
325
Test configuration
Windows XP, Dial-up connection, and a PC with 512MB of main memory, is one
possible configuration.
To ensure high reliability across the intended environments, the application must
be tested under as many test configurations, or environments, as possible.
326
Techniques we shall learn are useful in deriving test configurations as well as test
sets.
Contents
Foundations of Software Testing 2E
327
While testing a program with one or more input variables, each test run of a
program often requires at least one value for each variable.
For example, a program to find the greatest common divisor of two integers x and
y requires two values, one corresponding to x and the other to y.
Contents
Foundations of Software Testing 2E
328
Motivation
Motivation [2]
Contents
Foundations of Software Testing 2E
329
Once a partition is determined, one selects at random a value from each of the subdomains. Such a selection procedure, especially when using uni-dimensional
equivalence partitioning, does not account for the possibility of faults in the program
under test that arise due to specific interactions amongst values of different input
variables.
Contents
Foundations of Software Testing 2E
330
Motivation [3]
While boundary values analysis leads to the selection of test cases that test a
program at the boundaries of the input domain, other interactions in the input
domain might remain untested.
We will learn several techniques for generating test configurations or test sets that
are small even when the set of possible configurations or the input domain and the
number of sub-domains in its partition, is large and complex.
Contents
Foundations of Software Testing 2E
331
Motivation [4]
Contents
Foundations of Software Testing 2E
332
The input space of a program P consists of k-tuples of values that could be input
to P during execution.
The configuration space of P consists of all possible settings of the environment
variables under which P could be used.
Consider program P that takes two integers x>0 and y>0 as inputs. The input space of
P is the set of all pairs of positive non-zero integers.
Contents
Foundations of Software Testing 2E
333
Now suppose that this program is intended to be executed under the Windows and the
MacOS operating system, through the Netscape or Safari browsers, and must be able
to print to a local or a networked printer.
Contents
Foundations of Software Testing 2E
334
Consider a program P that takes n inputs corresponding to variables X1, X2, ..Xn. We
refer to the inputs as factors. The inputs are also referred to as test parameters or as
values.
Let us assume that each factor may be set at any one from a total of ci, 1 i n
values.
Contents
Foundations of Software Testing 2E
335
For example, suppose that program P has two input variables X and Y. Let us say
that during an execution of P, X and Y may each assume a value from the set
{a, b, c} and {d, e, f}, respectively.
Thus, we have 2 factors and 3 levels for each factor. This leads to a total of 32=9
factor combinations, namely (a, d), (a, e), (a, f), (b, d), (b, e), (b, f), (c, d), (c, e),
and (c, f).
Contents
Foundations of Software Testing 2E
336
Factor combinations
In general, for k factors with each factor assuming a value from a set of n values, the
total number of factor combinations is nk.
Suppose now that each factor combination yields one test case. For many
programs, the number of tests generated for exhaustive testing could be
exorbitantly large.
For example, if a program has 15 factors with 4 levels each, the total number of
tests is 415 ~109. Executing a billion tests might be impractical for many software
applications.
Contents
Foundations of Software Testing 2E
337
A PDS takes orders online, checks for their validity, and schedules Pizza for delivery.
A customer is required to specify the following four items as part of the online
order: Pizza size, Toppings list, Delivery address and a home phone number. Let
us denote these four factors by S, T, A, and P, respectively.
Contents
Foundations of Software Testing 2E
338
Suppose now that there are three varieties for size: Large, Medium, and Small.
There is a list of 6 toppings from which to select. In addition, the customer can
customize the toppings.
The delivery address consists of customer name, one line of address, city, and the
zip code. The phone number is a numeric string possibly containing the dash
(``--") separator.
Contents
Foundations of Software Testing 2E
339
340
The Graphical User Interface of application T consists of three menus labeled File,
Edit, and Format.
We have three factors in T. Each of these three factors can be set to any of four
levels. Thus, we have a total 43=64 factor combinations.
Contents
Foundations of Software Testing 2E
341
The sort utility has several options and makes an interesting example for the
identification of factors and levels. The command line for sort is given below.
sort [-cmu] [-ooutput] [-Tdirectory] [-y [ kmem]] [-zrecsz] [-dfiMnr] [-b] [ tchar] [kkeydef] [+pos1[-pos2]] [file...]
We have identified a total of 20 factors for the sort command. The levels listed in
Table 11.1 of the book lead to a total of approximately 1.9x109 combinations.
Contents
Foundations of Software Testing 2E
342
There is often a need to test a web application on different platforms to ensure that
any claim such as ``Application X can be used under Windows and Mac OS X are
valid.
Here we consider a combination of hardware, operating system, and a browser as a
platform. Let X denote a Web application to be tested for compatibility.
Given that we want X to work on a variety of hardware, OS, and browser
combinations, it is easy to obtain three factors, i.e. hardware, OS, and browser.
Contents
Foundations of Software Testing 2E
343
Contents
Foundations of Software Testing 2E
344
For example, Mac OS10.2 is an OS for the Apple computers and not for the Dell
Dimension series PCs. Similarly, the Safari browser is used on Apple computers and not
on the PC in the Dell Series.
While various editions of the Windows OS can be used on an Apple computer using an
OS bridge such as the Virtual PC, we assume that this is not the case for testing
application X.
Contents
Foundations of Software Testing 2E
345
There are 75 factor combinations. However, some of these combinations are infeasible.
Contents
Foundations of Software Testing 2E
346
While testing against all configurations will lead to more thorough testing of application
X, it will also increase the number of factor combinations, and hence the time to test.
Contents
Foundations of Software Testing 2E
347
Contents
Foundations of Software Testing 2E
348
Modeling of input space or the environment is not exclusive and one might apply either
one or both depending on the application under test.
Contents
Foundations of Software Testing 2E
349
350
Step 1: Model the input space and/or the configuration space. The model is expressed in
For example, consider the combination in which all factors are set to ``Unused" except
the -o option which is set to ``Valid File" and the file option that is set to ``Exists. Two
sample test cases are:
t1: sort -o afile bfile
t2: sort -o cfile dfile
Is one of the above tests sufficient?
Foundations of Software Testing 2E
351
Contents
Each combination obtained from the levels listed in Table 6.1 can be used to generate
case, the sequence in which inputs are to be applied to the program under test must be
determined by the tester.
Further, the factor combinations do not indicate in any way the sequence in which the
generated tests are to be applied to the program under test. This sequence too must be
determined by the tester.
The sequencing of tests generated by most test generation techniques must be determined
by the tester and is not a unique characteristic of test generated in combinatorial testing.
Contents
Foundations of Software Testing 2E
352
Combination of factor levels is used to generate one or more test cases. For each test
Contents
Foundations of Software Testing 2E
353
Faults aimed at by the combinatorial design techniques are known as interaction faults.
Of course, this invalid state must propagate to a point in the program execution where it
is observable and hence is said to reveal the fault.
Contents
Foundations of Software Testing 2E
354
Fault model
Faults triggered by some value of an input variable, i.e. t=1, regardless of the values of
other input variables, are known as simple faults.
In general, for any arbitrary value of t, the faults are known as t--way interaction faults.
Contents
Foundations of Software Testing 2E
355
Contents
Author: Aditya P. Mathur
356
This fault is triggered by all inputs such that x+yx-y and z 0. However,
the fault is revealed only by the following two of the eight possible input
combinations: x=-1, y=1, z=1 and x=-1, y=-1, z=1.
Contents
Foundations of Software Testing 2E
357
Given a set of k factors f1, f2,.., fk, each at qi, 1 i k levels, a vector V of factor
levels is (l1, l2,.., lk), where li, 1 i k is a specific level for the corresponding
factor. V is also known as a run.
A run V is a fault vector for program P if the execution of P against a test case
derived from V triggers a fault in P. V is considered as a t-fault vector if any t k
elements in V are needed to trigger a fault in P. Note that a t-way fault vector for P
triggers a t-way fault in P.
Contents
Foundations of Software Testing 2E
358
Fault vectors
Contents
Author: Aditya P. Mathur
359
Goal reviewed
The goal of the test generation techniques described in this chapter is to generate a
sufficient number of runs such that tests generated from these runs reveal all t-way
faults in the program under test.
Contents
Foundations of Software Testing 2E
360
The number of such runs increases with the value of t. In many situations, t is set to 2
and hence the tests generated are expected to reveal pairwise interaction faults.
Of course, while generating t-way runs, one automatically generates some t+1, t+2, .., t
+k-1, and k-way runs also. Hence, there is always a chance that runs generated with t=2
reveal some higher level interaction faults.
Contents
Foundations of Software Testing 2E
361
Goal reviewed
Contents
Foundations of Software Testing 2E
362
Latin Squares
that no symbol appears more than once in a row and column. The term ``Latin
square" arises from the fact that the early versions used letters from the Latin
alphabet A, B, C, etc. in a square arrangement.
363
Contents
Foundations of Software Testing 2E
364
A Latin square of order n>2 can also be constructed easily by doing modulo
arithmetic. For example, the Latin square M of order 4 given below is constructed
such that M(i, j)=i+j (mod 4), 1 (i, j) 4.
Contents
Foundations of Software Testing 2E
365
Contents
Foundations of Software Testing 2E
366
denote, respectively, the elements in the ith row and jth column of M1 and M2.
We now create an n x n matrix M from M1 and M2 such that the L(i, j) is M1(i,
j)M2(i, j), i.e. we simply juxtapose the corresponding elements of M1 and M2.
If each element of M is unique, i.e. it appears exactly once in M, then M1 and M2 are
said to be mutually orthogonal Latin squares of order n.
Contents
Foundations of Software Testing 2E
367
Let M1 and M2 be two Latin squares, each of order n. Let M1(i, j) and M2(i, j)
MOLS: Example
368
Contents
Foundations of Software Testing 2E
369
Example: We begin by constructing a Latin square of order 5 given the symbol set
S={1, 2, 3, 4, 5}.
Contents
Foundations of Software Testing 2E
370
Contents
Foundations of Software Testing 2E
371
positions, respectively.
Thus, we get MOLS(5)={M1, M2, M3, M4}. It is easy to check that indeed the elements
of MOLS(5) are mutually orthogonal by superimposing them pairwise.
Contents
Foundations of Software Testing 2E
372
M3 and M4 are obtained similarly but by rotating the first row of M1 by 3 and 4
The method illustrated in the previous example is guaranteed to work only when
constructing MOLS(n) for n that is prime or a power of prime. For other values of n, the
maximum size of MOLS(n) is n-1.
There is no general method available to construct the largest possible MOLS(n) for n
that is not a prime or a power of prime. The CRC Handbook of Combinatorial Designs
gives a large table of MOLS.
Contents
Foundations of Software Testing 2E
373
Contents
Foundations of Software Testing 2E
374
We will now look at a simple technique to generate a subset of factor combinations from
the complete set. Each combination selected generates at least one test input or test
configuration for the program under test.
Only 2-valued, or binary, factors are considered. Each factor can be at one of two levels.
This assumption will be relaxed later.
Contents
Foundations of Software Testing 2E
375
Pairwise designs
variable. Each variable can take only one of two distinct values.
Considering each input variable as a factor, the total number of factor combinations is 23.
Let X, Y, and Z denote the three input variables and {X1, X2}, {Y1, Y2}, {Z1, Z2} their
respective sets of values. All possible combinations of these three factors follow.
Contents
Foundations of Software Testing 2E
376
Suppose that a program to be tested requires 3 inputs, one corresponding to each input
There are 12 such pairs: (X1, Y1), (X1, Y2), (X1, Z1), (X1, Z2), (X2, Y1), (X2, Y2),
(X2, Z1), (X2, Z2), (Y1, Z1), (Y1, Z2), (Y2, Z1), and (Y2, Z2). The following four
combinations cover all pairs:
The above design is also known as a pairwise design. It is a balanced design because
each value occurs exactly the same number of times. There are several sets of four
combinations that cover all 12 pairs.
Contents
Foundations of Software Testing 2E
377
Now suppose we want to generate tests such that each pair appears in at least one test.
A Java applet ChemFun allows its user to create an in-memory database of chemical
elements and search for an element. The applet has 5 inputs listed after the next slide
with their possible values.
We refer to the inputs as factors. For simplicity we assume that each input has exactly
two possible values.
Contents
Foundations of Software Testing 2E
378
Contents
Foundations of Software Testing 2E
379
Contents
Foundations of Software Testing 2E
380
Contents
Foundations of Software Testing 2E
381
For k=3 we have S5= 10 and for k=2, S3= 3. Hence the desired integer k=3.
Contents
Foundations of Software Testing 2E
382
Select any subset of n strings from S2k-1. We have, k=3 and we have the following
strings in the set S5.
We select first five of the 10
strings in S5.
Contents
Foundations of Software Testing 2E
383
Append 0's to the end of each selected string. This will increase the size of each
string from 2k-1 to 2k.
Contents
Foundations of Software Testing 2E
384
Each combination is of the kind (X1, X2,, Xn), where the value of each variable is
selected depending on whether the bit in column i, 1 i n, is a 0 or a 1.
Contents
Foundations of Software Testing 2E
385
The following factor combinations by replacing the 0s and 1s in each column by the
corresponding values of each factor.
Contents
Foundations of Software Testing 2E
386
Contents
Foundations of Software Testing 2E
387
388
Contents
Foundations of Software Testing 2E
389
Next we will learn how to use MOLS to construct test configurations when:
Contents
Foundations of Software Testing 2E
390
One such facility is offered by The Applied Genomics Technology Center (AGTC)
at the School of Medicine in Wayne State University.
The submission of the sample itself is done using a software application available
from AGTC. We refer to this software as AGTCS.
Contents
Foundations of Software Testing 2E
391
and software configurations. Thus, the hardware platform and the operating system
are two factors to be considered while developing a test plan for AGTCS.
In addition, the user of AGTCS, referred to as PI, must either have a profile
already created with AGTCS or create a new one prior to submitting a sample.
AGTCS supports only a limited set of browsers.
For simplicity we consider a total of four factors with their respective levels given
next.
Contents
Foundations of Software Testing 2E
392
There are 64 combinations of the factors listed. As PCs and Macs run their
dedicated operating systems, the number of combinations reduces to 32.
We want to test under enough configurations so that all possible pairs of factor levels
are covered.
Contents
Foundations of Software Testing 2E
393
We can now proceed to design test configurations in at least two ways. One way is to
treat the testing on PC and Mac as two distinct problems and design the test
configurations independently. Exercise 6.12 asks you to take this approach and
explore its advantages over the second approach used in this example.
The approach used in this example is to arrive at a common set of test configurations
that obey the constraint related to the operating systems.
Contents
Foundations of Software Testing 2E
394
Input: n=4 factors. |F1|=2, |F2|=4, |F3|=4, |F4|=2, where F1, F2, F3, and F4
denote, respectively, hardware, OS, browser, and PI.
Output: A set of factor combinations such that all pairwise combinations are covered.
Contents
Foundations of Software Testing 2E
395
Reliable the factors as F1, F2, F3, F4 such that |F1||F2| |F3| |F4|.
Doing so gives us F1=F2', F2=F3', F3=F1', F4=F4', b=k=4. Note that a different
assignment is also possible because |F1|=|F4|and |F2|=|F3|.
Contents
Foundations of Software Testing 2E
396
Contents
Foundations of Software Testing 2E
397
Contents
Foundations of Software Testing 2E
398
Contents
Foundations of Software Testing 2E
399
From M2
From M1
400
Using the 16 entries in the table above, we can obtain 16 distinct test configurations
for AGTCS. However, we need to resolve two problems before we get to the design
of test configurations.
Problem 1: Factors F3 and F4 can only assume values 1 and 2 whereas the table above
contains other infeasible values for these two factors. These infeasible values are marked
with an asterisk.
Solution: One simple way to get rid of the infeasible values is to replace them by an
arbitrarily selected feasible value for the corresponding factor..
Contents
Foundations of Software Testing 2E
401
Problem 2: Some configurations do not satisfy the operating system constraint. Four
such configurations are highlighted in the design by enclosing the corresponding numbers
in rectangles. Here is an example:
Contents
402
Delete rows with conflicts?: Obviously we cannot delete these rows as that would leave
some pairs uncovered. Consider block 3.
Removing Row~3 will leave the following five pairs uncovered: (F1=3, F2=3), (F1=3,
F4=2), (F2=3, F3=1), (F2=3, F4=2), and (F3=1, F4=2).
Contents
Foundations of Software Testing 2E
403
Step 1: Modify the four highlighted rows so they do not violate the constraint.
Step 2: Add new configurations that cover the pairs that are left uncovered when we
replace the highlighted rows.
Contents
Foundations of Software Testing 2E
404
F4: PI
F3: Hardware
F1: OS
Contents
Foundations of Software Testing 2E
405
We can easily construct 20 test configurations from the design obtained. This
is in contrast to 32 configurations obtained using a brute force method.
Contents
Foundations of Software Testing 2E
406
A sufficient number of MOLS might not exist for the problem at hand.
While the MOLS approach assists with the generation of a balanced design in
that all interaction pairs are covered an equal number of times, the number of
test configurations is often larger than what can be achieved using other
methods.
Contents
Foundations of Software Testing 2E
407
Contents
Foundations of Software Testing 2E
408
Orthogonal arrays
An orthogonal array, such as the one above, is an N x k matrix in which the entries
are from a finite set S of s symbols such that any N x t sub array contains each t-tuple
exactly the same number of times. Such an orthogonal array is denoted by OA(N, k,
s, t).
Foundations of Software Testing 2E
Contents
Author: Aditya P. Mathur
409
The following orthogonal array has 4 runs and has a strength of 2. It uses symbols
from the set {1, 2}. This array is denoted as OA(4, 3, 2, 2). Note that the value of
parameter k is 3 and hence we have labeled the columns as F1, F2, and F3 to indicate
the three factors.
Contents
Foundations of Software Testing 2E
410
Contents
Foundations of Software Testing 2E
411
412
413
Contents
Foundations of Software Testing 2E
414
So far we have seen fixed level orthogonal arrays. This is because the
design of such arrays assumes that all factors assume values from the
same set of s values.
In many practical applications, one encounters more than one factor, each
taking on a different set of values. Mixed orthogonal arrays are useful in
designing test configurations for such applications.
Contents
Foundations of Software Testing 2E
415
Strength=t. Runs=N.
k1 factors at s1 levels, k2 at s2 levels, and so on.
Total factors:
Contents
Foundations of Software Testing 2E
416
The formula used for computing the index of an orthogonal array does not apply
to the mixed level orthogonal array as the count of values for each factor is a
variable.
The balance property of orthogonal arrays remains intact for mixed level
orthogonal arrays in that any N x t sub array contains each t-tuple corresponding to
the t columns, exactly the same number of times, which is .
Contents
Foundations of Software Testing 2E
417
418
419
We have 3 binary factors and one factor at 3 levels. Hence we can use the
following array to generate test configurations:
Contents
Foundations of Software Testing 2E
420
Contents
Foundations of Software Testing 2E
421
Contents
Foundations of Software Testing 2E
422
Contents
Foundations of Software Testing 2E
423
For example, if a software application has been tested once for a given pair of
factor levels, there is generally no need for testing it again for the same pair, unless
the application is known to behave non-deterministically.
For deterministic applications, and when repeatability is not the focus, we can relax
the balance requirement and use covering arrays, or mixed level covering arrays for
combinatorial designs.
Foundations of Software Testing 2E
Contents
Author: Aditya P. Mathur
424
Contents
Foundations of Software Testing 2E
425
Covering array
While an orthogonal array OA(N, k, s, t) covers each possible t-tuple times in any N
x t sub array, a covering array CA(N, k, s, t) covers each possible t-tuple at least
times in any N x t sub array.
Thus, covering arrays do not meet the balance requirement that is met by orthogonal
arrays. This difference leads to combinatorial designs that are often smaller in size than
orthogonal arrays.
Covering arrays are also referred to as unbalanced designs. We are interested in
minimal covering arrays.
Contents
Foundations of Software Testing 2E
426
OA(8, 5, 2, 2). However, a covering design with the same parameters requires only 6
runs.
Contents
Foundations of Software Testing 2E
427
A balanced design of strength 2 for 5 binary factors, requires 8 runs and is denoted by
i=1
array contains at least one occurrence of each t-tuple corresponding to the t columns.
s1, s2,, denote the number of levels of each the corresponding factor.
Mixed-level covering arrays are generally smaller than mixed-level orthogonal arrays
and more appropriate for use in software testing.
Contents
Foundations of Software Testing 2E
428
429
Contents
Foundations of Software Testing 2E
430
Designs with strengths higher than 2 are sometimes needed to achieve higher
confidence in the correctness of software. Consider the following factors in a
pacemaker.
Contents
Foundations of Software Testing 2E
431
Pacemaker example
Contents
432
Due to the high reliability requirement of the pacemaker, we would like to test it to
We will now study a procedure due to Lei and Tai for the generation of mixed level
covering arrays. The procedure is known as In-parameter Order (IPO) procedure.
Inputs: (a) n 2: Number of parameters (factors). (b) Number of values (levels) for
each parameter.
Output: MCA
Contents
Foundations of Software Testing 2E
433
Contents
Foundations of Software Testing 2E
434
IPO procedure
Contents
Foundations of Software Testing 2E
435
Consider a program with three factors A, B, and C. A assumes values from the set
{a1, a2, a3}, B from the set {b1, b2}, and C from the set {c1, c2, c3}. We want to
generate a mixed level covering array for these three factors..
We begin by applying the Main procedure which is the first step in the
generation of an MCA using the IPO procedure.
Contents
Foundations of Software Testing 2E
436
Main: Step 1: Construct all runs that consist of pairs of values of the first two
parameters. We obtain the following set.
as t1, t2,t6.
The entire IPO procedure would terminate at this point if the number of parameters
n=2. In our case n=3 hence we continue with horizontal growth.
Contents
Foundations of Software Testing 2E
437
HG: Step 1: Compute the set of all pairs AP between parameters A and C, and
parameters B and C. This leads us to the following set of fifteen pairs.
HG: Step 2: AP is the set of pairs yet to be covered. Let T denote the set of runs
obtained by extending the runs in T. At this point T is empty as we have not
extended any run in T.
Contents
Foundations of Software Testing 2E
438
HG: Steps 3, 4: Expand t1, t2, t3 by appending c1, c2, c3. This gives us:
t1=(a1, b1, c1), t2=(a1, b2, c2), and t3=(a2, b1, c3)
Update T which now becomes {a1, b1, c1), (a1, b2, c2), (a2, b1, c3)}
Update pairs remaining to be covered AP={(a1, c3), (a2, c1), (a2, c2), (a3, c1), (a3,
c2), (a3, c3), (b1, c2), (b2, c1), (b2, c3)}
Update T which becomes {(a1, b1, c1), (a1, b2, c2), (a2, b1, c3)}
Contents
Foundations of Software Testing 2E
439
HG. Step 5: We have not extended t4, t5, t6 as C does not have enough elements. We
find the best way to extend these in the next step.
If we extend t4=(a2, b2) by c1 then we cover two of the uncovered pairs from AP,
namely, (a2, c1) and (b2, c1). If we extend it by c2 then we cover one pair from AP.
If we extend it by c3 then we cover one pairs in AP. Thus, we choose to extend t4 by
c1.
Contents
Foundations of Software Testing 2E
440
T={(a1, b1, c1), (a1, b2, c2), (a2, b1, c3), (a2, b2, c1)}
AP= {(a1, c3), (a2, c2), (a3, c1), (a3, c2), (a3, c3), (b1, c2), (b2, c3)}
HG: Step 6: Similarly we extend t5 and t6 by the best possible values of parameter
C. This leads to:
t5=(a3, b1, c3) and t6=(a3, b2, c1)
T={(a1, b1, c1), (a1, b2, c2), (a2, b1, c3), (a2, b2, c1), (a3, b1, c3), (a3, b2, c1)}
AP= {(a1, c3), (a2, c2), (a3, c2), (b1, c2), (b2, c3)}
Contents
Foundations of Software Testing 2E
441
We have completed the horizontal growth step. However, we have five pairs
remaining to be covered. These are:
AP= {(a1, c3), (a2, c2), (a3, c2), (b1, c2), (b2, c3)}
We now move to the vertical growth step of the main IPO procedure to cover the
remaining pairs.
Contents
Foundations of Software Testing 2E
442
Vertical growth
For each missing pair p from AP, we will add a new run to T such that p is
covered. Let us begin with the pair p= (a1, c3).
The run t= (a1, *, c3) covers pair p. Note that the value of parameter Y does not
matter and hence is indicated as a * which denotes a dont care value.
Next , consider p=(a2, c2). This is covered by the run (a2, *, c2)
Next , consider p=(a3, c2). This is covered by the run (a3, *, c2)
Contents
Foundations of Software Testing 2E
443
to get the run (a1, b2, c3). Thus, p is covered without any new run added.
Finally, consider p=(b1, c2). We already have (a3, *, c2) and hence we can modify it
to get the run (a3, b1, c2). Thus, p is covered without any new run added.
We replace the dont care entries by an arbitrary value of the corresponding factor
and get:
T={(a1, b1, c1), (a1, b2, c2), (a1, b1, c3), (a2, b1, c2), (a2, b2, c1), (a2, b2, c3), (a3,
b1, c3), (a3, b2, c1), (a3, b1, c2)}
Contents
Foundations of Software Testing 2E
444
Next , consider p=(b2, c3). We already have (a1, *, c3) and hence we can modify it
MCA(9, 21 32, 2)
Run
F1(X)
F2(Y)
F3(Z)
Contents
Foundations of Software Testing 2E
445
Contents
Foundations of Software Testing 2E
446
Practicalities
Tools
Contents
Foundations of Software Testing 2E
447
Summary
Combinatorial design techniques assist with the design of test configurations and
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
test cases. By requiring only pair-wise coverage and relaxing the balance
requirement, combinatorial designs offer a significant reduction in the number of
test configurations/test cases.
MOLS, Orthogonal arrays, covering arrays, and mixed-level covering arrays are
used as combinatorial objects to generate test configurations/test cases. For
software testing, most useful amongst these are mixed level covering arrays.
Handbooks offer a number covering and mixed level covering arrays. We
introduced one algorithm for generating covering arrays. This continues to be a
research topic of considerable interest.
Contents
Foundations of Software Testing 2E
448
Contents
Author: Aditya P. Mathur
449
Chapter 7
Learning Objectives
What is test adequacy? What is test enhancement? When to measure test
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
450
Contents
Foundations of Software Testing 2E
451
What is adequacy?
Consider a program P written to meet a set R of functional requirements. We
notate such a P and R as ( P, R). Let R contain n requirements labeled R1,
R2,, Rn .
Suppose now that a set T containing k tests has been constructed to test P to
determine whether or not it meets all the requirements in R . Also, P has been
executed against each test in T and has produced correct behavior.
We now ask: Is T good enough? This question can be stated differently as: Has
P been tested thoroughly?, or as: Is T adequate?
Contents
452
Measurement of adequacy
In the context of software testing, the terms ``thorough," ``good enough," and
``adequate," used in the questions above, have the same meaning.
453
Example
R1
Input two integers, say x and y , from the standard input device.
R2.1
Find and print to the standard output device the sum of x and y if x<y .
R2.2
Find and print to the standard output device the product of x and y if x
y.
Contents
Foundations of Software Testing 2E
454
Example (contd.)
Contents
Foundations of Software Testing 2E
455
For each adequacy criterion C , we derive a finite set known as the coverage domain
and denoted as Ce .
A criterion C is a white-box test adequacy criterion if the corresponding coverage
domain Ce depends solely on program P under test.
A criterion C is a black-box test adequacy criterion if the corresponding
coverage domain Ce depends solely on requirements R for the program P
under test.
Contents
Foundations of Software Testing 2E
456
Coverage
We want to measure the adequacy of T. Given that Ce has n 0 elements, we say
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
that T covers Ce if for each element e' in Ce there is at least one test case in T
that tests e'. The notion of tests is explained later through examples.
457
In this case the finite set of elements Ce={R1, R2.1, R2.2}. T covers R1 and
R2.1 but not R2.2 . Hence T is not adequate with respect to C . The coverage of
T with respect to C, P, and R is 0.66.
Contents
Foundations of Software Testing 2E
458
Example
Assume that P has exactly two paths, one corresponding to condition x<y and the
other to x y. We refer to these as p1 and p2, respectively. For the given adequacy
criterion C we obtain the coverage domain Ce to be the set { p1, p2}.
Contents
Foundations of Software Testing 2E
459
Another Example
As T contains only one test for which x<y , only the path p1 is executed. Thus,
the coverage of T with respect to C, P , and R is 0.5 and hence T is not adequate
with respect to C. We can also say that p1 is tested and p2 is not tested.
Contents
Foundations of Software Testing 2E
460
In the previous example we assumed that P contains exactly two paths. This
assumption is based on a knowledge of the requirements. However, when the
coverage domain must contain elements from the code, these elements must be
derived by analyzing the code and not only by an examination of its requirements.
Errors in the program and incomplete or incorrect requirements might cause the
program, and hence the coverage domain, to be different from the expected.
Contents
Foundations of Software Testing 2E
461
Example
There is only one path denoted as p1. This path traverses all the statements. Using
the path-based coverage criterion C, we get coverage domain Ce={ p1}. T={t:
<x=2, y=3> }is adequate w.r.t. C but does not reveal the error.
Contents
Foundations of Software Testing 2E
462
sumProduct1
Example (contd.)
sumProduct2
This program is correct as per the requirements of
sumProduct. It has two paths denoted by p1 and p2.
Contents
Foundations of Software Testing 2E
463
Lesson
An adequate test set might not reveal even the most obvious error in a
program. This does not diminish in any way the need for the measurement
of test adequacy as increasing coverage might reveal an error!.
Contents
Foundations of Software Testing 2E
464
Contents
Foundations of Software Testing 2E
465
Test Enhancement
free program, an inadequate test set is a cause for worry. Inadequacy with respect to
any criterion often implies test deficiency.
Identification of this deficiency helps in the enhancement of the inadequate test set.
Enhancement in turn is also likely to test the program in ways it has not been tested
before such as testing untested portion, or testing the features in a sequence different
from the one used previously. Testing the program differently than before raises the
possibility of discovering any uncovered errors.
Contents
Foundations of Software Testing 2E
466
While a test set adequate with respect to some criterion does not guarantee an error-
For sumProduct2, to make T adequate with respect to the path coverage criterion we
need to add a test that covers p2. One test that does so is {<x=3>, y=1>}. Adding
this test to T and denoting the expanded test set by T' we get:
Executing sum-product-2 against the two tests in T causes paths p1 and p2 are
traversed. Thus, T' is adequate with respect to the path coverage criterion.
Contents
Foundations of Software Testing 2E
467
Contents
Foundations of Software Testing 2E
468
Contents
Foundations of Software Testing 2E
469
program for at least one zero and one non-zero value of each of the two
inputs x and y.
The coverage domain for C can be determined using C alone and without any
inspection of the program For C we get Ce={x=0, y=0}, x0, y 0. Again, one
can derive an adequate test set for the program by an examination of Ce. One
such test set is
T={t1: <x=0, y=1>, t2: <x=1, y=0>}.
Contents
Foundations of Software Testing 2E
470
Let us now consider the path coverage criterion defined in in an earlier example.
An examination of the exponentiation program reveals that it has an
indeterminate number of paths due to the while loop. The number of paths
depends on the value of y and hence that of count.
Contents
Foundations of Software Testing 2E
471
Given that y is any non-negative integer, the number of paths can be arbitrarily
large. This simple analysis of paths in exponentiation reveals that for the path
coverage criterion we cannot determine the coverage domain.
Contents
Foundations of Software Testing 2E
472
Contents
Foundations of Software Testing 2E
473
Contents
Foundations of Software Testing 2E
474
Contents
Foundations of Software Testing 2E
475
Contents
Foundations of Software Testing 2E
476
Infeasibility
There does not exist an algorithm that would analyze a given program and
determine if a given element in the coverage domain is infeasible or not. Thus, it is
usually the tester who determines whether or not an element of the coverage
domain is infeasible.
Contents
Foundations of Software Testing 2E
477
Demonstrating feasibility
Feasibility can be demonstrated by executing the program under test against a test
case and showing that indeed the element under consideration is covered.
478
Contents
Foundations of Software Testing 2E
479
480
considered adequate when all feasible elements in the domain have been covered.
Contents
Foundations of Software Testing 2E
481
In the presence of one or more infeasible elements in the coverage domain, a test is
Contents
Foundations of Software Testing 2E
482
The purpose of test enhancement is to determine test cases that test the untested
parts of a program or exercise the program using uncovered portions of the input
domain. Even the most carefully designed tests based exclusively on requirements
can be enhanced.
The more complex the set of requirements, the more likely it is that a test set designed
using requirements is inadequate with respect to even the simplest of various test
adequacy criteria.
Contents
Foundations of Software Testing 2E
483
Test enhancement
Example
Contents
Foundations of Software Testing 2E
484
Example (contd.)
Contents
Foundations of Software Testing 2E
485
Example (contd.)
Consider the following program written to meet the requirements stated earlier.
Contents
Foundations of Software Testing 2E
486
Example (contd.)
Contents
Foundations of Software Testing 2E
487
Example (contd.)
Contents
Foundations of Software Testing 2E
488
Example (contd.)
For the first two of the three requests the program correctly outputs 8 and 24,
respectively. The program exits when executed against the last request. This program
behavior is correct and hence one might conclude that the program is correct. It will
not be difficult for you to believe that this conclusion is incorrect.
Contents
Foundations of Software Testing 2E
489
Suppose now that the following set containing three tests has been developed to test
The coverage domain consists of all paths that traverse each of the three loops zero
and once in the same or different executions of the program. This is left as an exercise
and we continue with one sample, and tricky, uncovered path.
Contents
Foundations of Software Testing 2E
490
Example (contd.)
Example (contd.)
line 10, then the first if at line 12, followed by the statements that compute the
factorial starting at line 20, and then the code to compute the exponential starting at
line 13.
p is traversed when the program is launched and the first input request is to compute
the factorial of a number, followed by a request to compute the exponential. It is easy
to verify that the sequence of requests in T does not exercise p. Therefore T is
inadequate with respect to the path coverage criterion.
Contents
Foundations of Software Testing 2E
491
Consider the path p that begins execution at line 1, reaches the outermost while at
Example (contd.)
When the values in T' are input to our example program in the sequence given, the
program correctly outputs 24 as the factorial of 4 but incorrectly outputs 192 as the value
of 23 .
This happens because T' traverses our tricky path which makes the computation of the
exponentiation begin without initializing product. In fact the code at line 14 begins with
the value of product set to 24.
Contents
Foundations of Software Testing 2E
492
In our effort to increase the path coverage we constructed T' . Execution of the
program under test on T' did cover a path that was not covered earlier and revealed an
error in the program.
This example has illustrated a benefit of test enhancement based on code coverage.
Contents
Foundations of Software Testing 2E
493
Example (contd.)
Contents
Foundations of Software Testing 2E
494
Multiple executions
and T' contain three tests one for each value of variable request. Should T (or T) be
considered a single test or a sequence of three tests?
T={<request=2, x=4>, <request=1, x=2, y=3>, <request=3>}
we assumed that all three tests, one for each value of request, are input in a sequence
during a single execution of the test program. Hence we consider T as a test set
containing one test case and write it as follows:
Contents
Foundations of Software Testing 2E
495
In the previous example we constructed two test sets T and T' . Notice that both T
during a single execution of the test program. Hence we consider T as a test set
containing one test case and write it, it as follows:
T=TT
Contents
Foundations of Software Testing 2E
496
Contents
Foundations of Software Testing 2E
497
Some of these statements are declarative, such as the #define and int statements in C,
while others are executable, such as the assignment, if, and while statements in C and
Java.
Recall that a basic block is a sequence of consecutive statements that has exactly one
entry point and one exit point. For any procedural language, adequacy with respect to
the statement coverage and block coverage criteria are defined next.
498
Statement coverage
Contents
Foundations of Software Testing 2E
499
The block coverage of T with respect to (P, R) is computed as Bc/(Be -Bi) , where Bc
is the number of blocks covered, Bi is the number of unreachable blocks, and Be is
the total number of blocks in the program, i.e. the size of the block coverage domain.
T is considered adequate with respect to the block coverage criterion if the statement
coverage of T with respect to (P, R) is 1.
Contents
Foundations of Software Testing 2E
500
Block coverage
Statements covered:
t1: 2, 3, 4, 5, 6, 7, and 10
t2: 2, 3, 4, 9, and 10.
(b)
Contents
Foundations of Software Testing 2E
501
Blocks covered:
t1: Blocks 1, 2, 5
t2, t3: same coverage as of t1.
Be=5 , Bc=3, Bi=1.
Block coverage for T2= 3/(5-1)=0.75.
Hence T2 is not adequate for (P, R) with respect to
the block coverage criterion.
Contents
Foundations of Software Testing 2E
502
Contents
Foundations of Software Testing 2E
503
Coverage values
The formulae given for computing various types of code coverage, yield a
coverage value between 0 and 1. However, while specifying a coverage
value, one might instead use percentages. For example, a statement coverage
of 0.65 is the same as 65% statement coverage.
Contents
Foundations of Software Testing 2E
504
Contents
Foundations of Software Testing 2E
505
Conditions
Given that A , and B are Boolean variables, and x and y are integers, A ,
x > y , A OR B , A AND (x<y), (A AND B), are all sample conditions.
Note that in programming language C, x and x+y are valid conditions, and
the constants 1 and 0 correspond to, respectively, true and false.
Contents
Foundations of Software Testing 2E
506
A simple condition does not use any Boolean operators except for the not
operator. It is made up of variables and at most one relational operator from
the set {<, >, , ==, }. Simple conditions are also referred to as atomic
or elementary conditions because they cannot be parsed any further into two
or more conditions.
507
Conditions as decisions
high level languages provide if, while, and switch statements to serve as contexts for
decisions.
Contents
Foundations of Software Testing 2E
508
Any condition can serve as a decision in an appropriate context within a program. most
Outcomes of a decision
In some cases the evaluation of a condition might fail in which case the corresponding
decision's outcome is undefined.
Contents
Foundations of Software Testing 2E
509
A decision can have three possible outcomes, true, false, and undefined. When the
Contents
Foundations of Software Testing 2E
510
Undefined condition
How many simple conditions are there in the compound condition: Cond=(A AND B)
OR (C AND A)? The first occurrence of A is said to be coupled to its second
occurrence.
Does Cond contain three or four simple conditions? Both answers are correct
depending on one's point of view. Indeed, there are three distinct conditions A , B ,
and C. The answer is four when one is interested in the number of occurrences of
simple conditions in a compound condition.
Contents
Foundations of Software Testing 2E
511
Coupled conditions
Contents
Foundations of Software Testing 2E
512
Contents
Foundations of Software Testing 2E
513
Decision coverage
possible destinations that correspond to this decision, i.e. all outcomes of the decision
have been taken.
This implies that, for example, the expression in the if or a while statement has
evaluated to true in some execution of the program under test and to false in the same
or another execution.
Contents
Foundations of Software Testing 2E
514
A decision is considered covered if the flow of control has been diverted to all
more executions of the program under test the flow of control has been diverted to all
possible destinations.
Covering a decision within a program might reveal an error that is not revealed by
covering all statements and all blocks.
Contents
Foundations of Software Testing 2E
515
Contents
Foundations of Software Testing 2E
516
Contents
Foundations of Software Testing 2E
517
revealing an error that is not revealed by a test set adequate with respect to statement
and block coverage.
The decision coverage of T with respect to ( P, R ) is computed as Dc/(De -Di) , where
Dc is the number of decisions covered, Di is the number of infeasible decisions, and
De is the total number of decisions in the program, i.e. the size of the decision coverage
domain.
T is considered adequate with respect to the decisions coverage criterion if the decision
coverage of T with respect to ( P, R ) is 1.
Contents
Foundations of Software Testing 2E
518
The previous example illustrates how and why decision coverage might help in
The domain of decision coverage consists of all decisions in the program under test.
Note that each if and each while contribute to one decision whereas a switch
contribute to more than one.
Contents
Foundations of Software Testing 2E
519
Contents
Foundations of Software Testing 2E
520
Condition coverage
Contents
Foundations of Software Testing 2E
521
Contents
Foundations of Software Testing 2E
522
there is only one decision that leads control to line 2 if the compound condition
inside the if evaluates to true. However, a compound condition might evaluate to true
or false in one of several ways.
Contents
Foundations of Software Testing 2E
523
Contents
Foundations of Software Testing 2E
524
We now see two decisions, one corresponding to each simple condition in the if
statement.
Contents
Foundations of Software Testing 2E
525
Contents
Foundations of Software Testing 2E
526
Condition coverage
Contents
Foundations of Software Testing 2E
527
Contents
Foundations of Software Testing 2E
528
529
Contents
Foundations of Software Testing 2E
530
Condition/decision coverage
imply that each simple condition within a compound condition has taken both
values true and false.
Condition coverage ensures that each component simple condition within a
condition has taken both values true and false.
However, as illustrated next, condition coverage does not require each decision to
have taken both outcomes. Condition/decision coverage is also known as branch
condition coverage.
Contents
Foundations of Software Testing 2E
531
532
Contents
Foundations of Software Testing 2E
533
Contents
Foundations of Software Testing 2E
534
Contents
Foundations of Software Testing 2E
535
Consider a compound condition with two or more simple conditions. Using condition
coverage on some compound condition C implies that each simple condition within C
has been evaluated to true and false.
However, does it imply that all combinations of the values of the individual simple
conditions in C have been exercised?
Contents
Foundations of Software Testing 2E
536
Consider D=(A<B) OR (A>C) composed of two simple conditions A< B and A> C .
The four possible combinations of the outcomes of these two simple conditions are
enumerated in the table. Consider T:
Contents
Foundations of Software Testing 2E
537
Suppose that the program under test contains a total of n decisions. Assume also that
each decision contains k1, k2, , kn simple conditions. Each decision has several
combinations of values of its constituent simple conditions.
For example, decision i will have a total of 2ki combinations. Thus, the total
number of combinations to be covered is n
ki
i=1
Contents
Foundations of Software Testing 2E
538
The multiple condition coverage of T with respect to ( P, R ) is computed as Cc/(Ce Ci) , where Cc is the number of combinations covered,
Ci
Contents
Foundations of Software Testing 2E
539
Contents
Foundations of Software Testing 2E
540
Contents
Foundations of Software Testing 2E
541
Contents
Foundations of Software Testing 2E
542
Now add a test to T to cover the uncovered combinations. Does your test reveal the
error? If yes, then under what conditions?
Contents
Foundations of Software Testing 2E
543
Contents
Foundations of Software Testing 2E
544
where the first element of the pair is a sequence of statements, executed one after the
other, and terminated by a jump to the next such pair.
A Linear Code Sequence and Jump is a program unit comprised of a textual code
sequence that terminates in a jump to the beginning of another code sequence and
jump.
An LCSAJ is represented as a triple (X, Y, Z) where X and Y are, respectively,
locations of the first and the last statements and Z is the location to which the
statement at Y jumps.
Contents
Foundations of Software Testing 2E
545
Execution of sequential programs that contain at least one condition, proceeds in pairs
546
Contents
Foundations of Software Testing 2E
547
Contents
Foundations of Software Testing 2E
548
Contents
Foundations of Software Testing 2E
549
Contents
Foundations of Software Testing 2E
550
Contents
Foundations of Software Testing 2E
551
Obtaining multiple condition coverage might become expensive when there are many
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
Contents
Foundations of Software Testing 2E
552
Thus, MC/DC coverage is a weaker criterion than the multiple condition coverage
criterion.
Contents
Foundations of Software Testing 2E
553
Contents
Foundations of Software Testing 2E
554
Contents
Foundations of Software Testing 2E
555
columns as Test, C1, C2 , C3 and C, from left to right. An optional column labeled
Comments may be added. The column labeled Test contains rows labeled by test
case numbers t1 through t4 . The remaining entries are empty.
Contents
Foundations of Software Testing 2E
556
Let C=C1 and C2 and C3. Create a table with five columns and four rows. Label the
Copy all entries in columns C1 , C2 , and C from the table for simple conditions into
columns C2, C3, and C of the empty table.
Contents
Foundations of Software Testing 2E
557
Fill the first three rows in the column marked C1 with true and the last row with false.
Contents
Foundations of Software Testing 2E
558
Fill the last row under columns labeled C2 , C3 , and C with true, true, and false,
respectively.
We now have a table containing MC/DC adequate tests for C=(C1 AND C2 AND C3)
derived from tests for C=(C1 AND C2) .
Contents
Foundations of Software Testing 2E
559
The procedure illustrated above can be extended to derive tests for any compound
condition using tests for a simpler compound condition (solve Exercises 7.15 and
7.16).
Contents
Foundations of Software Testing 2E
560
Contents
Foundations of Software Testing 2E
561
with respect to the MC/DC coverage criterion if upon the execution of P on each test
in T, the following requirements are met.
Each simple condition in P has taken both true and false values.
Contents
Foundations of Software Testing 2E
562
Analysis
coverage, respectively.
The fourth requirement corresponds to ``MC" coverage. Thus, the MC/DC coverage
criterion is a mix of four coverage criteria based on the flow of control.
With regard to the second requirement, it is to be noted that conditions that are not part
of a decision, such as the one in the following statement A= (p<q) OR (x>y) are also
included in the set of conditions to be covered.
Contents
Foundations of Software Testing 2E
563
The first three requirements above correspond to block, condition, and decision
Analysis (contd.)
poses a problem. It is not possible to keep the first occurrence of A fixed while varying
the value of its second occurrence.
Here the first occurrence of A is said to be coupled to its second occurrence. In such
cases an adequate test set need only demonstrate the independent effect of any one
occurrence of the coupled condition
Contents
Foundations of Software Testing 2E
564
Adequacy
Let C1, C2, .., CN be the conditions in P. ni denote the number of simple conditions
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
565
Example
R1.3: Invoke fire-3 when none of the two conditions above is true.
R2: The invocation described above must continue until an input Boolean
variable becomes true.
Contents
Foundations of Software Testing 2E
566
Example (contd.)
Contents
Foundations of Software Testing 2E
567
Example (contd.)
Contents
Foundations of Software Testing 2E
568
Example (contd.)
Verify that the following set T1 of four tests, executed in the given order, is
adequate with respect to statement, block, and decision coverage criteria but not
with respect to the condition coverage criterion.
Contents
Foundations of Software Testing 2E
569
Example (contd.)
Verify that the following set T2, obtained by adding t5 to T1, is adequate with respect
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
to the condition coverage but not with respect to the multiple condition coverage
criterion. Note that sequencing of tests is important in this case!
Contents
Foundations of Software Testing 2E
570
Example (contd.)
Verify that the following set T3, obtained by adding t6, t7, t8, and t9 to T2 is adequate
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
with respect to MC/DC coverage criterion. Note again that sequencing of tests is
important in this case (especially for t1 and t7)!
Contents
Foundations of Software Testing 2E
571
Contents
Foundations of Software Testing 2E
572
573
Example
Suppose that condition C=C1 AND C2 AND C3 has been coded as C'=C1 AND C2. Four
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
tests that form an MC/DC adequate set are in the following table. Verify that the
following set of four tests is MC/DC adequate but does not reveal the error.
Contents
Foundations of Software Testing 2E
574
Several examples in the book show that satisfying the MC/DC adequacy criteria does not
necessarily imply that errors made while coding conditions will be revealed. However,
the examples do favor MC/DC over condition coverage.
The examples also show that an MC/DC adequate test will likely reveal more errors
than a decision or condition-coverage adequate test. (Note the emphasis on likely.)
Contents
Foundations of Software Testing 2E
575
The outcome of the above condition does not depend on C2 when C1 is false. When
using short-circuit evaluation, condition C2 is not evaluated if C1 evaluates to false.
Thus, the combination C1=false and C2=true, or the combination C1=false and
C2=false may be infeasible if the programming language allows, or requires as in
C, short circuit evaluation.
Contents
Foundations of Software Testing 2E
576
Contents
Foundations of Software Testing 2E
577
not feasible and vice versa. In the sequence above, both decisions are reachable but the
second decision is not feasible. Consider the following sequence.
Contents
Foundations of Software Testing 2E
578
Note that infeasibility is different from reachability. A decision might be reachable but
Contents
Foundations of Software Testing 2E
579
following question: What portions of the requirements are tested when the program
under test is executed against the newly added test case? The task of relating the new
test case to the requirements is known as test trace-back.
Advantages of trace back: Assists us in determining whether or not the new test
case is redundant.
It has the likelihood of revealing errors and ambiguities in the requirements.
It assists with the process of documenting tests against requirements.
See example 7.27.
Contents
Foundations of Software Testing 2E
580
When enhancing a test set to satisfy a given coverage criterion, it is desirable to ask the
Contents
Foundations of Software Testing 2E
581
Basic concepts
We will now examine some test adequacy criteria based on the flow of data in a
program. This is in contrast to criteria based on flow of control that we have
examined so far.
Test adequacy criteria based on the flow of data are useful in improving tests that
are adequate with respect to control-flow based criteria. Let us look at an example.
Contents
Foundations of Software Testing 2E
582
Contents
Foundations of Software Testing 2E
583
Example (contd.)
Contents
584
Example (contd.)
Verify that the following test set covers all def-use pairs of z and reveals the
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
error.
585
Contents
Foundations of Software Testing 2E
586
Contents
Foundations of Software Testing 2E
587
The first of the above statements defines a pointer variable z the second defines y
and uses z the third defines x through the pointer variable z and the last defines y
and uses x accessed through the pointer variable z.
Contents
Foundations of Software Testing 2E
588
The first statement defines variable A. The second statement defines A and uses i , x,
and y. Alternate: second statement defines A[i] and not the entire array A. The
choice of whether to consider the entire array A as defined or the specific element
depends upon how stringent is the requirement for coverage analysis.
Contents
Foundations of Software Testing 2E
589
Arrays are also tricky. Consider the following declaration and two statements in C:
Contents
Foundations of Software Testing 2E
590
c-use
Answer: 5
Contents
Foundations of Software Testing 2E
591
p-use
The occurrence of a variable in an expression used as a condition in a branch
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
How many p-uses of z and x can you find in the following statements?
Answer: 3 (2 of z and 1 of x)
Contents
592
Contents
Foundations of Software Testing 2E
593
While there are two definitions of p in this block, only the second definition will
propagate to the next block. The first definition of p is considered local to the block
while the second definition is global. We are concerned with global definitions, and
uses.
Note that y and z are global uses; their definitions flow into this block from some
other block.
Contents
Foundations of Software Testing 2E
594
Contents
Foundations of Software Testing 2E
595
A data-flow graph of a program, also known as def-use graph, captures the flow of
definitions (also known as defs) across basic blocks in a program.
It is similar to a control flow graph of a program in that the nodes, edges, and all
paths thorough the control flow graph are preserved in the data flow graph. An
example follows.
Contents
Foundations of Software Testing 2E
596
Example
block. Each block becomes a node in the def-use graph (this is similar to the
control flow graph).
Attach defs, c-use and p-use to each node in the graph. Label each edge with the
condition which when true causes the edge to be taken.
We use di(x) to refer to the definition of variable x at node i. Similarly, ui(x) refers to
the use of variable x at node i.
Contents
Foundations of Software Testing 2E
597
Given a program, find its basic blocks, compute defs, c-uses and p-uses in each
Example (contd.)
Unreachable node
Contents
Foundations of Software Testing 2E
598
Contents
Foundations of Software Testing 2E
599
Def-clear path
Any path starting from a node at which variable x is
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
600
P7.16
601
Contents
Contents
Foundations of Software Testing 2E
602
Def-use pairs
603
Def of a variable at line l1 and its use at line l2 constitute a def-use pair. l1 and l2
Contents
Foundations of Software Testing 2E
604
of a def-use pair implies coverage of another def-use pair. Analysis of the data flow
graph can reveal a minimal set of def-use pairs whose coverage implies coverage of all
def-use pairs.
Exercise: Analyze the def-use graph shown in the previous slide and determine a
minimal set of def-uses to be covered.
Contents
Foundations of Software Testing 2E
605
Def-use pairs are items to be covered during testing. However, in some cases, coverage
Contents
Foundations of Software Testing 2E
606
Contents
Foundations of Software Testing 2E
607
C-use coverage
Contents
Foundations of Software Testing 2E
608
Contents
Foundations of Software Testing 2E
609
Contents
Foundations of Software Testing 2E
610
p-use coverage
Contents
Foundations of Software Testing 2E
611
Contents
Foundations of Software Testing 2E
612
Contents
Foundations of Software Testing 2E
613
All-uses coverage
Contents
Foundations of Software Testing 2E
614
Infeasible uses are often difficult to determine without some hint from a test
tool.
Contents
Foundations of Software Testing 2E
615
Contents
Foundations of Software Testing 2E
616
Contents
Foundations of Software Testing 2E
617
There exist several other adequacy criteria based on data flows. Some of these are
more powerful in their error-detection effectiveness than the c-, p-, and all-uses
criteria.
Examples: (a) def-use chain or k-dr chain coverage. These are alternating sequences
of def-use for one or more variables. (b) Data context and ordered data context
coverage.
Contents
Foundations of Software Testing 2E
618
Contents
Foundations of Software Testing 2E
619
Subsumes: Given a test set T that is adequate with respect to criterion C1, what can
we conclude about the adequacy of T with respect to another criterion C2?
Effectiveness: Given a test set T that is adequate with respect to criterion C, what can
we expect regarding its effectiveness in revealing errors?
Contents
Foundations of Software Testing 2E
620
Subsumes relation
Subsumes relationship
Contents
Foundations of Software Testing 2E
621
Summary
Contents
Foundations of Software Testing 2E
622
Summary (contd.)
during testing and displays it in a user-friendly manner. xSUDS is one such set of
tools. Several other commercial tools, such as PaRTe, Cobertura, and Bullseye, are
available.
Several test organizations believe that code coverage is useful at unit-level. This is a
myth and needs to be shattered. Incremental assessment of code coverage and
enhancement of tests can allow the application of coverage-based testing to large
programs.
Contents
Foundations of Software Testing 2E
623
Use of any of the criteria discussed here requires a test tool that measures coverage
Even though coverage is not guaranteed to reveal all program errors, it is the perhaps
the most effective way to assess the amount of code that has been tested and what
remains untested.
Tests derived using black-box approaches can almost always be enhanced using one
or more of the assessment criteria discussed.
Contents
Foundations of Software Testing 2E
624
Summary (contd.)
Chapter 8
Test Adequacy Measurement and
Enhancement Using Mutation
Contents
Author: Aditya P. Mathur
625
Learning Objectives
What is test adequacy? What is test enhancement? When to measure test
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
Mutation operators
626
What is adequacy?
Consider a program P written to meet a set R of functional requirements. We
notate such a P and R as ( P, R). Let R contain n requirements labeled R1,
R2,, Rn .
Suppose now that a set T containing k tests has been constructed to test P to
determine whether or not it meets all the requirements in R . Also, P has been
executed against each test in T and has produced correct behavior.
We now ask: Is T good enough? This question can be stated differently as: Has
P been tested thoroughly?, or as: Is T adequate?
Contents
Foundations of Software Testing 2E
627
Suppose that program P has been tested against a test set T and P has not failed
on any test case in T. Now suppose we do the following:
Changed to
P
Contents
Foundations of Software Testing 2E
628
P is known as a mutant of P.
There might be a test t in T such that P(t)P(t). In this case we say that t
distinguishes P from P. Or, that t has killed P.
There might be not be any test t in T such that P(t)P(t). In this case we say that
T is unable to distinguish P and P. Hence P is considered live in the test
process.
Contents
629
If there does not exist any test case t in the input domain of P that distinguishes P
from P then P is said to be equivalent to P.
630
Given a test set T for program P that must meet requirements R, a test adequacy
assessment procedure proceeds as follows.
Step 1: Create a set M of mutants of P. Let M={M0, M1Mk}. Note that we have
k mutants.
Step 2: For each mutant Mi find if there exists a t in T such that Mi(t) P(t). If
such a t exists then Mi is considered killed and removed from further
consideration.
Contents
631
Step 3: At the end of Step 2 suppose that k1 k mutants have been killed and (kk1) mutants are live.
Case 1: (k-k1)=0: T is adequate with respect to mutation.
Case 2: (k-k1)>0 then we compute the mutation score (MS) as follows:
MS=k1/(k-e)
where e is the number of equivalent mutants. Note: e (k-k1).
Contents
632
One has the opportunity to enhance a test set T after having assessed its
adequacy.
Step 1: If the mutation score (MS) is 1, then some other technique, or a different
set of mutants, needs to be used to help enhance T.
Step 2: If the mutation score (MS) is less than 1, then there exist live mutants that
are not equivalent to P. Each live mutant needs to be distinguished from P.
Contents
633
Step 3: Hence a new test t is designed with the objective of distinguishing at least
one of the live mutants; let us say this mutant is m.
Contents
Foundations of Software Testing 2E
634
Contents
Foundations of Software Testing 2E
635
As with any test enhancement technique, there is no guarantee that tests derived
to distinguish live mutants will reveal a yet undiscovered error in P. Nevertheless,
empirical studies have found to be the most powerful of all formal test
enhancement techniques.
The next simple example illustrates how test enhancement using mutation detects
errors.
Contents
Foundations of Software Testing 2E
636
Consider the following function foo that is required to return the sum of two
integers x and y. Clearly foo is incorrect.
int foo(int x, y){
return (x-y);
Contents
Foundations of Software Testing 2E
637
Now suppose that foo has been tested using a test set T that contains two tests:
T={ t1: <x=1, y=0>, t2: <x=-1, y=0>}
First note that foo behaves perfectly fine on each test in, i.e. foo returns the
expected value for each test case in T. Also, T is adequate with respect to all
control and data flow based test adequacy criteria.
Contents
638
Let us evaluate the adequacy of T using mutation. Suppose that the following
three mutants are generated from foo.
M1: int foo(int x, y){
return (x+y);
return (x-0);
return (0+y);
639
Next we execute each mutant against tests in T until the mutant is distinguished
or we have exhausted all tests. Here is what we get.
T={ t1: <x=1, y=0>, t2: <x=-1, y=0>}
Test (t)
foo(t)
M1(t)
M2(t)
M3(t)
t1
t2
-1
-1
-1
Live
Live
Killed
Contents
640
In class exercise: Determine whether or not the two live mutants are equivalent
to foo and compute the mutation score of T.
Contents
Foundations of Software Testing 2E
641
return (x+y);
return (x-0);
642
return (x+y);
return (x-0);
In class exercise: (a) Will any test that distinguishes also reveal the error? (b)
Will any test that distinguishes M2 reveal the error?
Contents
Foundations of Software Testing 2E
643
Sometimes there exists a mutant P of program P such that any test t that
distinguishes P from P also causes P to fail. More formally:
Let P be a mutant of P and t a test in the input domain of P. We say
that P is an error revealing mutant if the following condition holds
for any t.
P(t) P(t) and P(t) R(t), where R(t) is the expected response of P
based on its requirements.
Is M1 in the previous example an error revealing mutant? What about
M2?
Contents
Foundations of Software Testing 2E
644
Distinguishing a mutant
A test case t that distinguishes a mutant m from its parent program P program
must satisfy the following three conditions:
Condition 1: Reachability: t must cause m to follow a path that arrives at the
mutated statement in m.
Condition 2: Infection: If Sin is the state of the mutant upon arrival at the
mutant statement and Sout the state soon after the execution of the mutated
statement, then Sin Sout.
Contents
Foundations of Software Testing 2E
645
Contents
Foundations of Software Testing 2E
646
Equivalent mutants
The problem of deciding whether or not a mutant is equivalent to its
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
The number of equivalent mutants can vary from one program to another.
However, empirical studies have shown that one can expect about 5% of
the generated mutants to the equivalent to the parent program.
647
A misconception
There is a widespread misconception amongst testing educators, researchers, and
practitioners that any coverage based technique, including mutation, will not be
Correct program
int foo(int x, y){
int p=0;
int p=0;
if(x<y)
Missing else
able to detect errors due to missing path. Consider the following programs.
if(x<y)
p=p+1;
p=p+1;
return(x+p*y)
else
p=p-1;
return(x+p*y)
}
Contents
648
A misconception [2]
(a) Suggest at least one mutant M of foo that is guaranteed to reveal the error;
in other words M is an error revealing mutant.
(b) Suppose T is decision adequate for foo. Is T guaranteed to reveal the error?
(c) Suppose T is def-use adequate for foo. Is T guaranteed to reveal the error?
Contents
Foundations of Software Testing 2E
649
Mutant operators
A mutant operator O is a function that maps the program under test to a set
of k (zero or more) mutants of P.
M1
O(P)
M2
.
Mk
Contents
Foundations of Software Testing 2E
650
Contents
Foundations of Software Testing 2E
651
In mutant
Variable replacement
z=x*y+1;
x=x*y+1;
z=x*x+1;
Relational operator
replacement
if (x<y)
if(x>y)
if(x<=y)
Off-by-1
z=x*y+1;
z=x*(y+1)+1;
z=(x+1)*y+1;
Replacement by 0
z=x*y+1;
z=0*y+1;
z=0;
Arithmetic operator
replacement
z=x*y+1;
z=x*y-1;
z=x+y-1;
Mutant operator
Contents
Foundations of Software Testing 2E
652
order.
A mutant obtained by making two changes is a second order mutant.
Similarly higher order mutants can be defined. For example, a second
order mutant of z=x+y; is x=z+y; where the variable replacement operator
has been applied twice.
In practice only first order mutants are generated for two reasons: (a) to
lower the cost of testing and (b) most higher order mutants are killed by
tests adequate with respect to first order mutants. [See coupling effect
later.]
Contents
653
programmer
654
is Thus, evident that two groups might arrive at a different set of mutation
operators for the same programming language. How should we judge
whether or not that a set of mutation operators is good enough?
Informal definition:
655
Contents
Foundations of Software Testing 2E
656
657
658
It is Thus, safe to assume that when asked to write a program to sort a list
of numbers, a competent programs knows of, and makes use of, at least
one sorting algorithm. Mistakes will lead to a program that can be
corrected by applying one or more first order mutations.
Contents
659
Coupling effect
The coupling effect has been paraphrased by DeMillo, Lipton, and
Contents
Foundations of Software Testing 2E
660
the state space of the program under test. This perturbation takes place at
the point of mutation and has the potential of infecting the entire state of
the program.
Contents
Foundations of Software Testing 2E
661
There are few mutation testing tools available freely. Two such tools are
Proteum for C from Professor Jos Maldonado and muJava for Java from
Professor Jeff Offutt. We are not aware of any commercially available
tool for mutation testing. See the textbook for a more complete listing of
mutation tools.
Contents
Foundations of Software Testing 2E
662
Execution of the program under test against T and saving the output for
Generation of mutants.
Contents
Foundations of Software Testing 2E
663
Contents
Foundations of Software Testing 2E
664
However, given a good tool, one can use mutation to assess adequacy of
system tests.
665
secure functioning of the application. Repeat the following steps for each
unit in U.
Contents
Foundations of Software Testing 2E
666
Step 5: Repeat Steps 3 and 4 for the next unit until all units have been
considered.
We have now assessed T, and perhaps enhanced it. Note the use of
incremental testing and constrained mutation (i.e., use of a limited set of
highly effective mutation operators).
Contents
Foundations of Software Testing 2E
667
Contents
Foundations of Software Testing 2E
668
Summary
Mutation testing is the most powerful technique for the assessment and
enhancement of tests.
Contents
Foundations of Software Testing 2E
669
Summary [2]
While mutation testing is often recommended for unit testing, when done
Contents
Foundations of Software Testing 2E
670
Contents
Author: Aditya P. Mathur
671
Chapter 9
Learning Objectives
Contents
Foundations of Software Testing 2E
672
Contents
Foundations of Software Testing 2E
673
Regression testing
Contents
Foundations of Software Testing 2E
674
Idea 1:
All valid tests from the previous version and new tests created to test
any added functionality. [This is the TEST-ALL approach.]
Contents
Foundations of Software Testing 2E
675
The test-all approach is best when you want to be certain that the the
new version works on all tests developed for the previous version
and any new tests.
But what if you have limited resources to run tests and have to meet
a deadline? What if running all tests as well as meeting the deadline
is simply not possible?
Contents
Foundations of Software Testing 2E
676
Test selection
Idea 2:
Select a subset Tr of the original test set T such that successful
execution of the modified code P against Tr implies that all the
functionality carried over from the original code P to Pis intact.
Contents
Foundations of Software Testing 2E
677
Contents
Foundations of Software Testing 2E
678
679
Test selection
Test setup
Now that we know what the regression test selection problem is, let us
look at an overall regression test process.
Test sequencing
Test execution
Error correction
Output analysis
In this chapter we will learn how to select tests for regression testing.
Contents
Foundations of Software Testing 2E
680
Contents
Foundations of Software Testing 2E
681
Step 1: Given P and test set T, find the execution trace of P for each test in T.
Step 2: Extract test vectors from the execution traces for each node in the
CFG of P
Step 3: Construct syntax trees for each node in the CFGs of P and P. This
step can be executed while constructing the CFGs of P and P.
Step 4: Traverse the CFGs and determine the a subset of T appropriate for
regression testing of P.
Contents
Foundations of Software Testing 2E
682
Let G=(N, E) denote the CFG of program P. N is a finite set of nodes and E
a finite set of edges connecting the nodes. Suppose that nodes in N are
numbered 1, 2, and so on and that Start and End are two special nodes as
discussed in Chapter 1.
Let Tno be the set of all valid tests for P. Thus, Tno contains only tests valid
for P. It is obtained by discarding all tests that have become obsolete for
some reason.
Contents
Foundations of Software Testing 2E
683
Contents
Foundations of Software Testing 2E
684
An execution trace of program P for some test t in Tno is the sequence of nodes in
Contents
Foundations of Software Testing 2E
685
Now consider the following set of three tests and the corresponding trace.
Contents
Foundations of Software Testing 2E
686
Test vector
A test vector for node n, denoted by test(n), is the set of tests that traverse node n
in the CFG. For program P we obtain the following test vectors.
Contents
Foundations of Software Testing 2E
687
Syntax trees
A syntax tree is constructed for each node of CFG(P) and CFG(P). Recall that
Copyright 2013 Dorling Kindersley (India) Pvt. Ltd
each node represents a basic block. Here sample syntax trees for the example
program.
Contents
Foundations of Software Testing 2E
688
Given the execution traces and the CFGs for P and P, the following three steps
are executed to obtain a subset T of T for regression testing of P.
Contents
Foundations of Software Testing 2E
689
The basic idea underlying the SelectTests procedure is to traverse the two CFGs
from their respective START nodes using a recursive descent procedure.
The descent proceeds in parallel and the corresponding nodes are compared. If
two two nodes N in CFG(P) and N in CFG( P) are found to be syntactically
different, all tests in test (N) are added to T.
Contents
Foundations of Software Testing 2E
690
Try the SelectTests algorithm and check if you get T={t1, t3}.
Contents
Foundations of Software Testing 2E
691
Think:
What tests will be selected when only, say, one declaration is modified?
Can you think of a way to select only tests that correspond to variables in the
modified declaration?
Contents
Foundations of Software Testing 2E
692
Contents
Foundations of Software Testing 2E
693
The dynamic slice of P with respect to t and v, denoted as DS(t, v, L), is the
set of statements in P that (a) lie in trace(t) and (b) effected the value of v at
L.
Question: What is the dynamic slice of P with respect to v and t if L is not in
trace(t)?
Contents
Foundations of Software Testing 2E
694
Dynamic slice
695
696
should be
3 if(f1(x)==0)
3
Contents
697
trace(t)={1, 2, 3, 4, 6, 7, 2, 3, 5, 6, 7, 2, 8}
trace(t)={1, 2, 3, 4, 6, 7, 2, 3, 5, 6, 7, 2, 8}
Continuing this way we obtain the following DDG for
program P and trace(t).
should be
3 if(f1(x)==0)
Contents
Foundations of Software Testing 2E
698
Contents
Foundations of Software Testing 2E
699
Contents
Foundations of Software Testing 2E
700
Let T be the test set used to test P. P is the modified program. Let n1, n2, ..nk
be the nodes in the CFG of P modified to obtain P. Which tests from T should
be used to obtain a regression test T for P?
Find DS(t) for P. If any of the modified nodes is in DS(t) then add t to T.
Contents
Foundations of Software Testing 2E
701
In class exercise
Contents
Foundations of Software Testing 2E
702
Teasers [1]
You may have noticed that a DDG could be huge, especially for large
programs. How can one reduce the size of the DDG and still obtain the
correct DS?
The DS contains all statements in trace(t) that had an effect on w, the
variable of interest. However there could be a statement s in trace(t) that
did not have an effect but could affect w if changed. How can such
statements be identified? [Hint: Read about potential dependence.]
Contents
Foundations of Software Testing 2E
703
Teasers [2]
Suppose statement s in P is deleted to obtain P? How would you find
the tests that should be included in the regression test suite?
Suppose statement s is added to P to obtain P? How would you find the
tests that should be included in the regression test suite?
In our example we used variable w to compute the dynamic slice. While
selecting regression tests, how would you select the variable for which
to obtain the dynamic slice?
Contents
Foundations of Software Testing 2E
704
Contents
Foundations of Software Testing 2E
705
Test minimization is yet another method for selecting tests for regression
testing.
To illustrate test minimization, suppose that P contains two functions,
main and f. Now suppose that P is tested using test cases t1 and t2.
During testing it was observed that t1 causes the execution of main but
not of f and t2 does cause the execution of both main and f.
Contents
Foundations of Software Testing 2E
706
Now suppose that P is obtained from P by making some modification
to f.
Which of the two test cases should be included in the regression test
suite?
Obviously there is no need to execute P against t1 as it does not cause
the execution of f. Thus, the regression test suite consists of only t2.
In this example we have used function coverage to minimize a test suite
{t1, t2} to a obtain the regression test suite {t2}.
Contents
Foundations of Software Testing 2E
707
Test minimization is based on the coverage of testable entities in P.
Testable entities include, for example, program statements, decisions,
def-use chains, and mutants.
One uses the following procedure to minimize a test set based on a
selected testable entity.
Contents
Foundations of Software Testing 2E
708
Step 1: Identify the type of testable entity to be used for test minimization.
Let e1, e2, ..ek be the k testable entities of type TE present in P. In
our previous example TE is function.
Step 2: Execute P against all elements of test set T and for each test t in T
determine which of the k testable entities is covered.
Step 3: Find a minimal subset Tof T such that each testable entity is
covered by at least one test in T.
Contents
Foundations of Software Testing 2E
709
blocks for a sample program are shown here for both main and
function f1.
Step 2: Suppose the coverage of the basic
blocks when executed against three
tests is as follows:
t1: main: 1, 2, 3. f1: 1, 3
t2: main: 1, 3. f1: 1, 3
t1: main: 1, 3. f1: 1, 2, 3
Step3: A minimal test set for regression
testing is {t1, t3}.
Contents
Foundations of Software Testing 2E
710
Is the minimal test set unique? Why or why not?
Is test minimization NP hard? How is the traditional set cover problem in
mathematics related to the test minimization problem?
What criteria should be used to decide the kind of
testable entity to be used for minimization?
Contents
Foundations of Software Testing 2E
711
Contents
Foundations of Software Testing 2E
712
Test prioritization
Note that test minimization will likely discard test cases. There is a small
chance that if P were executed against a discarded test case it would reveal
an error in the modification made.
When very high quality software is desired, it might not be wise to discard
test cases as in test minimization. In such cases one uses test prioritization.
Tests are prioritized based on some criteria. For example, tests that cover the
maximum number of a selected testable entity could be given the highest
priority, the one with the next highest coverage m the next higher priority
and so on.
Contents
Foundations of Software Testing 2E
713
Step 1:
Identify the type of testable entity to be used for test minimization.
Let e1, e2, ..ek be the k testable entities of type TE present in P. In
our previous example TE is function.
Step 2:
Execute P against all elements of test set T and for each test t in T.
For each t in T compute the number of distinct testable entities
covered.
Step
3:
Arrange the tests in T in the order of their respective coverage. Test
with the maximum coverage gets the highest priority and so on.
Contents
Foundations of Software Testing 2E
714
Once the tests are prioritized one has the option of using all tests for
regression testing or a subset. The choice is guided by several factors
such as the resources available for regression testing and the desired
product quality.
In any case test are discarded only after careful consideration that does
not depend only on the coverage criteria used.
Contents
Foundations of Software Testing 2E
715
9.10. Tools
Contents
Foundations of Software Testing 2E
716
717
Summary [1]
Contents
Foundations of Software Testing 2E
718
Summary [2]
Test selection for regression testing can be done using any of the following
methods:
Select only the modification traversing tests [based on CFGs].
Select tests using execution slices [based on execution traces].
Select tests using dynamic slices [based on execution traces and dynamic
slices].
Select tests using code coverage [based on the coverage of testable entities].
Contents
Foundations of Software Testing 2E
719
Summary [3]
Contents
Foundations of Software Testing 2E
720
Chapter 10
Unit Testing
[Under Construction]
Contents
Foundations of Software Testing 2E
721
Chapter 11
Integration Testing
[Under Construction]
Contents
Foundations of Software Testing 2E
722