View
214
Download
0
Embed Size (px)
Citation preview
1
Software Testing and Quality Assurance
Lecture 8 - Software Testing Techniques
2
Lecture Outline Discuss testing techniques based on
achieving coverage of the software. Control-flow testing Data-flow testing
Static Data-flow testing
3
Coverage Based Testing To achieve some form of coverage of
the program-under- test based on well-defined-criteria Rather than partitioning the input domain of
the program.
4
Control-flow Testing Aims to understand the flow of control within
a program. Select test inputs to exercise paths in the Control-
Flow Graph (CFG). Paths are selected based on the control
information in the graph. Examples of coverage criteria include:
Path coverage Branch coverage condition coverage
5
Control-flow Graphs Control-flow is a graph G = (V,E) where;
Vertex represents a program statement Edge represents the ability of a program to
flow from its current statement to the next statement.
If an edge is associated with a conditional statement, label the edge with the conditional value, either true or false.
6
Control-flow Graphs - ExampleInt power (int base, int n){
int power i;power = 1;for (i = 1; I ≤ n; i ++) {
power = base * power;}
Return power;}
7
Control-flow Graphs - Example
int base, int n
int power, 1
Power = 1
i = 1
I ≤ n Power = base * power
i = i + 1
return power
8
Branch or decision
Control-flow Graphs - Example
int base, int n
int power, 1
Power = 1
i = 1
I ≤ n Power = base * power
i = i + 1
return power
Execution Path Condition
9
Coverage Based Criteria Statement - every statement of the program
should be exercised at least once. Branch coverage - every possible alternative
in a branch of the program should be tested at least once.
Condition coverage - each condition in a branch is made to evaluate to true or false.
10
Coverage Based Criteria Multiple condition coverage
All possible combinations of condition outcomes within each branch should be exercised at least once.
For example, if (a&&b) --- evaluate all possible combinations.
Path coverage Every execution path of the program
should be exercised at least once.
11
Data-Flow Testing Despite analysis of input and output
domains used in Equivalence partitioning, boundary value
analysis, and control flow Testing relies on personal experience to
choose test cases.
For example, program with 5 input variables3125 possible EC
12
Data-Flow Testing Information about the creation and use
of data definitions in a program. Detect many single programming or logical
faults in the program; Provide testers with dependencies
between the definitions and use of variables.
Complement coverage based testing.
13
Static Data-Flow Testing Simplest form of data-flow analysis A programming language statement can
act on a variable in 3 different ways. Define a variable Reference a variable Undefined a variable
14
Static Data-Flow Testing - Define (d) A statement defines a variable by
assigning a value to a variable. For example,
x = 5; Scan (x);
x = 3 * y;
Defined the variable x
Only defined the variable xIf y is declared and defined.
15
Static Data-Flow Testing - Reference (r) A statement makes a reference to a variable
either as an: I-value - variable, array cell into which values can
be stored. A variable that appears on the left hand side of an
assignment statement. R -value - any variable that must be referenced to
get its value. A variable that appears on the right hand side of an
assignment statement.
16
Static Data-Flow Testing - Un-define (u) A statement un-defines a variable
whenever the value of the variable becomes unknown.
For example, The scope of a local variable ends.
17
Static Data-Flow Testing - Anomalies u-r anomaly
Undefined variable is referenced. For example, un-initialized variable.
d-u anomaly A defined variable has not been referenced before
it becomes undefined. d-d anomaly
Same variable is defined twice. Usually due to misspelling or because variables
have been imported from another function.
18
Int i,j; int *c;
C = malloc(….)
c = Null
C [0] = 1; c[1] = 1; sum = 2;
Error (….)
i = 2
I ≤ n
C [i] = c[I-1] + c[I-2]; sum += c[I];
Return sum;
Fee (c)
I++
A
B
C
True
DFalse
E
F
GH False
I
J
K
Action on variable cNo action
Define
reference
No action
reference
Un-define
No action
u-r anomaly
19
Key points Control-Flow Testing aims to understand the
flow of control within a program. Most common - Control-Flow Graph
Data-Flow Testing Provides additional information to use for program
analysis and testing. Static Data-Flow Analysis
Typing errors Un-initialized variables, Misspelling of names etc.
20
Announcement Quiz 2 moved from
Wednesday 29/10/2008 to Saturday 01/11/2008.
Material Lec 6, Lec 7,Lec 8 & Lec 9