11 White Box Testing Control Flow Testing - Done
11 White Box Testing Control Flow Testing - Done
Levels of Coverage
Level 0 to Level 7
2
Control Flow Basis Path Data Flow
Testing Testing Testing
CONTROL FLOW TESTING
Identifies the execution paths
Decision Point
Junction point
STEP 1: NUMBER THE
EXAMPLE CODE LINES
q=1
b=2 1. q=1
c=3 2. b=2
if (a==2) 3. c=3
{x=x+2;} 4. if (a==2)
else 5. {x=x+2;}
{x=x/2;} 6. else
p=q/r; 7. {x=x/2;}
G
When the code is finished an
END NODE is formed. H
STEP 3: PATHS IN GRAPH ARE
ANALYZED A
1. abdefgh
B
2. abcefgh
C D
3. abdefh
E
4. abcefh
F
G
H
STEP 4: TEST CASES ARE
CREATED 1. q=1
A
x 100
(%)
BRANCH COVERAGE
// An updated computeFine() function
TC#1
1
TC#2
1
int computerFine (int daysLate, boolean printOn)
{
1 int MAX_FINE_PERIOD = 21, fine = MAX_FINE; 2 2
//defect fixed T T
F F
2 if (daysLate <= MAX_FINE_PERIOD) {
3 fine = daysLate * DAILY_FINE; 3 3
}
4 logFine (fine); 4 4
5 if (printON == TRUE) {
6 printFine(fine);
}
7 return fine; 5 5
Tests sufficient to}satisfy Branch Coverage T T
Test daysLate printON Path Coverage % Coverage F F
Case #
6 6
1 1 TRUE 1-2-3-4-5-6-7 75%
2 7
2 60 FALSE 1-2-4-5-7 50% 7
BRANCH COVERAGE
BRANCH COVERAGE 1
// Another updated function computeFines()
int computerFine (int daysLate[], int numDVD, boolean printOn) F
2
{
1 int MAX_FINE_PERIOD = 21, int cumFine = 0; T
2 for (i=0; i<numDVD; i++) { 3
3 fine=MAX_FINE;
4 if (daysLate[i]<=MAX_FINE_PERIOD) {
5 fine=daysLate[i] * DAILY_FINE; 4 T
} F
6 logFine (fine); 5
7 if (printON == TRUE) { 6
8 printFine(fine);
} T
7
9 cumFine += fine; 8
} F
10 return cumFine; 9
} Tests sufficient to satisfy Branch Coverage
Test i<numDVD daysLate [i] printON Path Coverage % Coverage
Case #
10
.
.
CONDITIONAL COVERAGE
For more complexed statements
Enough test cases are written so that each condition that has a true and false outcome
that makes up a decision is evaluated at least once.
If first part of condition is checked and is true the second expression will not be
evaluated (in logical operation or case).
The next level of control flow coverage is "100% condition coverage." At this level enough test
cases are written so that each condition that has a TRUE and FALSE outcome that makes up a
decision is evaluated at least once.
This level of coverage can be achieved with two test cases (a>0, c=1, b=3, d<0 and a≤0, c≠1,
b≠3, d≥0).
Condition coverage is usually better than decision coverage because every individual condition
is tested at least once while decision coverage can be achieved without testing every condition.
CONDITION/DECISION
COVERAGE
Consider this situation:
if(x&&y) {conditionedStatement;}
We can achieve condition coverage with two test cases (x=TRUE, y=FALSE and x=FALSE,
y=TRUE) but note that with these choices of data values the conditionedStatement will never
be executed.
Given the possible combination of conditions such as these, to be more complete "100%
decision/condition" coverage can be selected.
At this level test cases are created for every condition and every decision.
MULTIPLE CONDITIONAL
COVERAGE
To be even more thorough, consider how the programming language compiler actually
evaluates the multiple conditions in a decision. Use that knowledge to create test cases
yielding "100% multiple condition coverage.“
Achieving 100% multiple condition coverage also achieves decision coverage, condition
coverage, and decision/condition coverage.
Note that multiple condition coverage does not guarantee path coverage.
PATH COVERAGE
// An updated computeFine() function
int computerFine (int daysLate, boolean printOn)
{
1 int MAX_FINE_PERIOD = 21, fine = MAX_FINE;
//defect fixed
Path#1 Path#2 Path#3 Path#4
2 if (daysLate <= MAX_FINE_PERIOD) {
3 fine = daysLate * DAILY_FINE;
1 1 1 1
}
4 logFine (fine);
2 2 2 2
5 if (printON == TRUE) {
F T F T F T F T
6 printFine(fine);
3 3 3 3
}
7 return fine; 4 4 4 4
Test daysLate } printOn Path
Case #
5 5 5 5
1 1 True 1-2-3-4-5-6-7
T T T T
2 60 False 1-2-4-5-7 F F F F
6 6 6 6
3 1 False 1-2-3-4-5-7
7 7 7 7
4 60 True 1-2-4-5-6-7
PATH COVERAGE (LOOPS)
When a module has loops in the code paths such that the number of paths is infinite, a
significant but meaningful reduction can be made by limiting loop execution to a small
number of cases.
the first case is to execute the loop zero times;
the second is to execute the loop one time,
the third is to execute the loop n times
where n is a small number representing a typical loop value;
Before beginning control flow testing, an appropriate level of coverage should be chosen.
PATH COVERAGE (LOOPS)
0 times
1 time
N times (100)
Its Maximum number m times
Optional : m-1, m+1
for (i=1;i<=1000;i++)
for (j=1;j<=1000;j++)
for (k=1;k<=1000;k++)
do this (i, j, k)
DRAWBACKS IF WE DO EXHAUSTIVE
TESTING
2. How to handle if some path has been missed?
if (a>0)
callGreater ();
if (a==0)
callEquals()
a=a-1;//actual
DRAWBACKS IF WE DO EXHAUSTIVE
TESTING
4. Module may execute correctly for all data except for a few.