Software Testing and Quality Assurance
Download
Report
Transcript Software Testing and Quality Assurance
Software Testing and Quality
Assurance
Lecture 8 - Software Testing
Techniques
1
Lecture Outline
Discuss testing techniques based on
achieving coverage of the software.
Control-flow testing
Data-flow testing
Static Data-flow testing
2
Coverage Based Testing
To achieve some form of coverage of
the program-under- test based on welldefined-criteria
Rather than partitioning the input domain of
the program.
3
Control-flow Testing
Aims to understand the flow of control within
a program.
Select test inputs to exercise paths in the ControlFlow Graph (CFG).
Paths are selected based on the control
information in the graph.
Examples of coverage criteria include:
Path coverage
Branch coverage
condition coverage
4
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.
5
Control-flow Graphs Example
Int power (int base, int n)
{
int power i;
power = 1;
for (i = 1; I ≤ n; i ++) {
power = base * power;
}
Return power;
}
6
Control-flow Graphs Example
int base, int n
int power, 1
Power = 1
i=1
i=i+1
I≤n
Power = base * power
return power
7
Control-flow Graphs Example
int base, int n
Execution Path
int power, 1
Condition
Power = 1
i=1
Branch or decision
i=i+1
I≤n
Power = base * power
return power
8
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.
9
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.
10
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 variables
3125 possible EC
11
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.
12
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
13
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 x
If y is declared and defined.
14
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.
15
Static Data-Flow Testing - Undefine (u)
A statement un-defines a variable
whenever the value of the variable
becomes unknown.
For example,
The scope of a local variable ends.
16
Static Data-Flow Testing Anomalies
u-r anomaly
d-u anomaly
Undefined variable is referenced.
For example, un-initialized variable.
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.
17
Action on variable c
Error (….)
Int i,j; int *c;
A
No action
C = malloc(….)
B
Define
C
c = Null
False
D
reference
C [0] = 1; c[1] = 1; sum = 2;
i=2
H
Return sum;
False
E
No action
F
G
I≤n
True
reference
C [i] = c[I-1] + c[I-2]; sum += c[I];
Fee (c)
J
Un-define
No action
I++
u-r anomaly
I
K
18
Key points
Control-Flow Testing aims to understand the
flow of control within a program.
Data-Flow Testing
Most common - Control-Flow Graph
Provides additional information to use for program
analysis and testing.
Static Data-Flow Analysis
Typing errors
Un-initialized variables,
Misspelling of names etc.
19
Announcement
Quiz 2 moved from
Wednesday 29/10/2008 to
Saturday 01/11/2008.
Material
Lec 6, Lec 7,Lec 8 & Lec 9
20