Testing Methods in Software
Testing Methods in Software
Rajib Mall
CSE Department
IIT KHARAGPUR
1
MC/DC Testing
2
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 should
independently affect the outcome of each decision
• Requires: If( (A==0) (B>5) (C<100)) ….
Requirement 2:
Requirement 3:
true false
◼ This is as in Branch coverage.
7
MC/DC Requirement 2
• Test cases make every condition in the decision to
evaluate to both T and F at least once.
true false
true false true false
8
MC/DC Requirement 3
• Every condition in the decision independently affects the decision’s
outcome. If ( && ) then…
( a>10 ) (( b<50 ) || ( c==0 ))
9
MC/DC: An Example
• N+1 test cases required for N basic conditions
• Example:
((((a>10 || b<50) && c==0) || d<5) && e==10)
Test a>10 b<50 c==0 d<5 e==10 outcome
Case
(1) true false true false true true
(2) false true true false true true
(3) true false false true true true
(6) true false true false false false
(11) true false false false true false
(13) false false true false true false
- 1 + 2 + 3
4 F F F
11
If( (A B) C) ….
A B C Result A B C MC/DC
Another
1
2
1
1
1
1
1
0
1
0 * * Example
* **
3 1 0 1 1
*
4
5
0
1
1
0
1
0
1
0 * *
6 0 1 0 0
7
8
0
0
0
0
1
0
0
0 * * *
If (A and (B or C)) then… Minimal Set Example
TC# ABC Result A B C We want to determine the MINIMAL
set of test cases
1 TTT T 5
Here:
2 TTF T 6 4
• {2,3,4,6}
3 TFT T 7 4
4 TFF F 2 3 •{2,3,4,7}
5 FTT F 1
6 FTF F 2 Non-minimal set is:
7 FFT F 3 •{1,2,3,4,5}
8 FFF F
Observation MCC
Statement
• MC/DC essentially is : MC/DC: Summary
– basic condition coverage (C)
– branch coverage (DC)
– plus one additional condition (M):
every condition must independently affect the decision’s output
03/08/10 16
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.
int f1(int x,int y){ Example
1
1 while (x != y){
2 if (x>y) then 2
3 x=x-y;
3 4
4 else y=y-x;
5
5 }
6 return x; } 6
• Every program is composed of:
– Sequence
How to Draw Control flow Graph?
– 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
–1 a=5;
–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?
1
• Iteration:
– 1 while(a>b){
2
–2 b=b*a;
–3 b=b-1;}
3
– 4 c=b+d;
4
Path
• A path through a program:
3
4
Linearly Independent Path
• Any path through the program that:
–Introduces at least one new edge: 1
•Not included in any other 2
independent paths.
3
4
• It is straight forward: Independent path
–To identify linearly independent paths of simple
programs.
2 Cyclomatic
complexity =
3 4 7-6+2 = 3.
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.
1 Example
Control
2 Flow Graph
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
03/08/10 46
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?
statement
weakest coverage
condition branch
coverage (or decision)
coverage
White-Box
branch and condition
(or condition /decision)
coverage
Testing
Practically important
coverage techniques independent path
modified condition / (or basis path)
decision coverage
coverage
multiple- condition
coverage
49
Data Flow-Based Testing
–X is defined at a statement S:
–X in DEF(S)
–X in USES(S1), and
59
• In this, software is first tested: Mutation Testing
–Using an initial test suite designed using white-box strategies we
already discussed.
• After the initial testing is complete,
Mutation
Mutation Tests
Problem
New Test
with
Mutant Test Tests?
Cases
Mutants
Yes
Mutants that are
Any Live Test
caught by tests are
killed
Mutants? No Complete
Dead
Mutants