Software Testing w3 - Watermark
Software Testing w3 - Watermark
03/08/10 1
Recap: Condition Testing
• Simple or (basic) Condition Testing:
Test cases make each atomic condition to have both
T and F values
a=15, b=30
a=5, b=60
Test a b c d e
Case
(1) T — T — T
2 =32
5
(2) F T T — T
(3) T — F T T
(4) F T F T T
(5) F F — T T
•Short-circuit
(6) T — T — F
(7) F T T — F evaluation often
(8) T — F T F
reduces number of test
(9) F T F T F
(10) F F — T F cases to a more
(11) T — F F — manageable number,
(12) F T F F —
(13) F F — F — but not always…
Modified Condition/Decision Coverage (MC/DC)
• Motivation: Effectively test important
combinations of conditions, without
exponential blowup to test suite size:
“Important” combinations means: Each basic
condition shown to independently affect the
outcome of each decision
• Requires: If( (A==0) (B>5) (C<100)) ….
For each basic condition c, two test cases
Values of all evaluated conditions except c
remain the same
Compound condition as a whole evaluates to
true for one and false for the other
Test Coverage Criteria
Condition/Decision Coverage
Condition: true, false. Subsumption hierarchy
Requirement 2:
Requirement 3:
true false
true false
true false true false
14
MC/DC Requirement 3
• Every condition in the decision independently
affects the decision’s outcome.
Show independence of A :
Test
A B Decision Test Test
1 1 1 1 1
2 1 1 0 0 * *
3 1 0 1 1 * **
4 0 1 1 1 *
5 1 0 0 0 * *
6 0 1 0 0
7 0 0 1 0
8 0 0 0 0 * * *
Minimal Set Example
If (A and (B or C)) then…
TC# ABC Result A B C
We want to
determine the
1 TTT T 5 MINIMAL set of
test cases
2 TTF T 6 4
Here:
3 TFT T 7 4
• {2,3,4,6}
4 TFF F 2 3
•{2,3,4,7}
5 FTT F 1
6 FTF F 2
7 FFT F 3 Non-minimal set is:
8 FFF F •{1,2,3,4,5}
Critique
• MC/DC criterion is
MCC
stronger than
condition/decision coverage MC/DC
criterion,
Condition/Decision
but the number of test cases to
achieve the MC/DC criterions
Decision
still linear in the number of
conditions n in the decisions. Statement
MC/DC: Summary
• MC/DC essentially is :
basic condition coverage (C)
branch coverage (DC)
plus one additional condition (M):
every condition must independently affect the
decision’s output
03/08/10 22
Path Coverage
• Design test cases such that:
All linearly independent paths in
the program are executed at least
once.
• Defined in terms of
Control flow graph (CFG) of a
program.
Path Coverage-Based Testing
• To understand the path coverage-
based testing:
We need to learn how to draw control
flow graph of a program.
• A control flow graph (CFG) describes:
The sequence in which different
instructions of a program get executed.
The way control flows through the
program.
How to Draw Control Flow Graph?
• Number all statements of a program.
• Numbered statements:
Represent nodes of control flow graph.
• Draw an edge from one node to another
node:
If execution of the statement
representing the first node can result
in transfer of control to the other
node.
Example
int f1(int x,int y){
1 while (x != y){
2 if (x>y) then
3 x=x-y;
4 else y=y-x;
5 }
6 return x; }
Example Control Flow Graph
3 4
5
6
How to Draw Control flow Graph?
• Every program is composed of:
Sequence
Selection
Iteration
• If we know how to draw CFG
corresponding these basic
statements:
We can draw CFG for any program.
How to Draw Control flow Graph?
• Sequence:
1 a=5;
1
2 b=a*b-1;
2
How to Draw Control Flow Graph?
• Selection:
1 if(a>b) then 1
2 c=3;
3 else c=5; 2 3
4 c=c*c;
4
How to Draw Control Flow Graph?
• Iteration:
1
1 while(a>b){
2 b=b*a; 2
3 b=b-1;}
4 c=b+d; 3
4
Path
• A path through a program:
08/10/1003/08/10
Linearly Independent Path
• Any path through the
program that:
Introduces at least one new
edge:
•Not included in any other
independent paths.
Independent path
• It is straight forward:
V(G)= E-N+2
1
Cyclomatic
2 complexity =
7-6+2 = 3.
3 4
5
6
Cyclomatic Complexity
• Another way of computing
cyclomatic complexity:
inspect control flow graph
determine number of bounded areas
in the graph
• V(G) = Total number of bounded
areas + 1
Any region enclosed by a nodes and edge
sequence.
Example Control Flow Graph
1
3 4
6
Example
• From a visual examination of
the CFG:
Number of bounded areas is 2.
Cyclomatic complexity = 2+1=3.
Cyclomatic Complexity
• McCabe's metric provides:
• A quantitative measure of testing
difficulty and the reliability
• Intuitively,
Number of bounded areas increases
with the number of decision nodes
and loops.
Cyclomatic Complexity
• The first method of computing
V(G) is amenable to automation:
You can write a program which
determines the number of nodes
and edges of a graph
3 4
5
6
Derivation of Test Cases
• Number of independent paths: 3
1,6 test case (x=1, y=1)
03/08/10 55
White Box Testing: Quiz
1. What do you mean by coverage-based
testing?
2. What are the different types of
coverage based testing?
3. How is a specific coverage-based
testing carried out?
4. What do you understand by fault-
based testing?
5. Give an example of fault-based
testing?
White-Box Testing : Recap
statement
weakest coverage
condition branch
coverage (or decision)
coverage
03/08/10 58
Data Flow-Based Testing
X is defined at a statement S:
X in DEF(S)
X in USES(S1), and
• Assume:
03/08/10 68
Mutation Testing
• In this, software is first tested:
Program
If program is
not error-free,
fix it
Create
Mutants Test
Process
Mutation
Mutation Tests Problem
New Test
with
Mutant Test
Tests?
Cases
Mutants
Yes
break; break;
Disadvantages of Mutation Testing
• Equivalent mutants
• Disadv:
Equivalent mutants
Integration
Testing
03/08/10 84
Integration Testing Approaches
M1
M2 M3 M4
M5 M6 M7 M7
M8
Example Structured Design
M1
M2 M3 M4
M5 M6 M7 M7
M8
Big bang Integration Testing
M1
M2 M3 M4
M5 M6 M7 M7
M8