0% found this document useful (0 votes)
23 views

Software Testing CS4153 - 3

Uploaded by

logindummy007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Software Testing CS4153 - 3

Uploaded by

logindummy007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

White Box Testing Techniques

• Statement coverage: This technique makes sure that all executable


statements in the code are run and tested at least once.
• Branch coverage: In this technique, the code is mapped into the branches
of conditional logic and ensures that unit tests cover every branch.
• Path coverage: In this technique, the tester writes unit tests to execute all
the possible paths through the program’s control flow in order to identify
broken, redundant, and inefficient paths.
• Control flow testing: It is a structural testing technique that helps
determine the execution order of statements of the program through a
control structure.
Path Coverage
• A structural white-box testing method called path coverage
testing is used in software testing to examine and confirm that
every possible path through a program’s control flow has been
tested at least once.
• This approach looks at the program’s source code to find different
paths, which are collections of statements and branches that
begin at the entry point and end at the exit point of the program.
Example:
def • Path 1 (amount > 100): If you
test with
calculate_discount(amount): calculate_discount(120), it
discount = 0 should return a discount of 10.
if amount > 100:
discount = 10 • Path 2 (amount <= 100): If you
test with
else: calculate_discount(80), it
discount = 5 should return a discount of 5.
return discount
Steps Involved in Path Coverage Testing:
• Step #1) Code Interpretation: • Step #8) Coverage Evaluation:
• Step #2) Construction of a Control • Step #9) Analysis of Cyclomatic
Flow Graph (CFG): Complexity:
• Step #3) Calculating the Cyclomatic • Step #10) Find Unexplored Paths:
Complexity: • Step #11) Improve and iterate:
• Step #4) Determine Paths: • Step #12) Re-execution:
• Step #5) Path counting: • Step #13) Examining and Validating:
• Step #6) Test Case Design: • Step #14) Report and supporting
• Step #7) Run the Test: materials
Path CoverageTesting
• 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.
• To understand the path coverage-based testing:
we need to learn how to draw control flow graph of a program.
Control Flow Graph
• A control flow graph (CFG) describes: the sequence in
which different instructions of a program get executed.
• the way control flows through the program.

• Different branches, loops, and decision points are all


included in the test cases’ execution of the code.
Control Flow Graph
How to draw Control flow graph?
• Number all the statements of a program.
• Numbered statements:
represent nodes of the control flow graph.
• An edge from one node to another node exists:
if execution of the statement representing the first node
 can result in transfer of control to the other node.
Example_1
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; }
CFG-
Ex_1
Example_2
Sequence:
1 a=5;
2 b=a*b-1;
• Selection:

• For(i=0;i>b;i++)
1 if(a>b) then
2 c=3;
3 else c=5;
4 c=c*c;
Example_3
1. for(i=0;i>b;i++)
2. {if(a>b) then c=3;
3. else
4. c=5;
5. c=c*c;
6. }
7. Print;
Example_4
• Iteration:
1 do{
2 b=b*a;
3 b=b-1;}
4 }while(a>b)
5 c=b+d;
Path
• A path through a program:
a node and edge sequence from the starting node to a
terminal node of the control flow graph.
There may be several terminal nodes for program.

Independent Path
• Any path through the program:
introducing at least one new node:
 that is not included in any other independent paths.
Independent Path
• It is straight forward:
• to identify linearly independent paths of simple
programs.
• For complicated programs:
• it is not so easy to determine the number of
independent paths.
McCabe's cyclomatic metric
• An upper bound:
for the number of linearly independent paths of a program

• Provides a practical way of determining:


the maximum number of linearly independent paths in a
program.

• Given a control flow graph G, cyclomatic complexity V(G):


• V(G)= E-N+2, where
• N is the number of nodes in G
• E is the number of edges in G
Example:
• Cyclomatic complexity = 7-6+2 = 3.
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


• Bounded Area: Any region enclosed by a nodes and
edge sequence.
• From a visual examination of the CFG:
the number of bounded areas is 2.
cyclomatic complexity = 2+1=3.

You might also like