SE Chapter Four Final
SE Chapter Four Final
1 3 3 50%
2 7 21 50%
Branch Coverage Testing
▪ In most cases a decision has two outcomes (True or False),
but it is possible for a decision to have more outcomes, for
example, in “case of ...” statements.
▪ Branch coverage technique is used to cover all branches of
the control flow graph.
➢ It covers all the possible outcomes (true and false) of each
condition of decision point at least once.
▪ Branch coverage technique is a white box testing technique
that ensures that every branch of each decision point must be
executed.
Branch Coverage Testing Cont.
▪ branch coverage technique and decision coverage technique
are very similar, but there is a key difference between the two.
➢ Decision coverage technique covers all branches of each decision
point whereas branch testing covers all branches of every decision
point of the code.
▪ In other words, branch coverage follows decision point and
branch coverage edges.
▪ Many different metrics can be used to find branch coverage
and decision coverage, but some of the most basic metrics
are: finding the percentage of program and paths of execution
during the execution of the program.
▪ Like decision coverage, it also uses a control flow graph to
calculate the number of branches.
Branch Coverage Testing Cont.
Home work.
▪ Condition testing may be weaker than decision testing. Why ?
Multiple Condition Testing
▪ With this test technique we test combinations of condition
outcomes.
▪ To get 100% multiple combination coverage we must test all
combinations of outcomes of all conditions.
▪ Because there are two possible outcomes for each condition (True
and False) it requires 2n test cases, where n is the number of
conditions, to get 100% coverage.
▪ Example :if (X or (Y and Z)) then ..
▪ we have three conditions. We therefore need 23 = 8 test cases to get
100% multiple condition coverage.
▪ The test cases we need are:
Multiple Condition Testing Cont.
▪ A “-” means that we don’t care about what the outcome is, because
it does not have impact on the result.
▪ We can hence get 100% modified condition decision coverage or
condition determination coverage with just four test cases.
Path Testing
▪ A path is a sequence of executable statements in a component from
an entry point to an exit point.
▪ Path coverage is the percentage of paths in a component exercised
by the test cases.
▪ When you execute test cases based on any of the other structure-
based techniques described above, you will inevitably execute paths
through the code.
▪ Four stages are followed to create test cases using this technique −
➢ Create a Control Flow Graph.
➢ Calculate the Graph's Cyclomatic Complexity
➢ Identify the Paths That Aren't Connected
➢ Create test cases based on independent paths.
Path Testing Cont.
Control Flow Graph
▪ A control flow graph (or simply flow graph) is a directed graph that
depicts a program's or module's control structure.
▪ V number of nodes/vertices and E number of edges make up a
control flow graph (V, E).
▪ A control graph can also include the following
➢ A node with multiple arrows entering it is known as a
junction node.
➢ A node having more than one arrow leaving it is called a
decision node.
➢ The area encompassed by edges and nodes is referred to as a
region (area outside the graph is also counted as a region.).
Path Testing Cont.
▪ Switch – Case
Path Testing Cont.
▪ Cyclomatic Complexity
➢what is measurement ?
Measurement :- is noting but quantitative indication of size ,
dimension , capacity of an attributes of products or processes .
✓ Example :Numbers of errors
➢ What is software metrics?
Software metrics is defined as quantitative measure of an attribute a
software system process with respect to cost, quality, size and
schedule.
✓ Example : numbers of errors found per person.
Cyclomatic Complexity is a software metric used to measure the
complexity of a program.
➢ It is quantitative measure of independent paths in the source code of the
program.
Path Testing Cont.
▪ independent path is defined as a path that has at least one edge
which has not been traversed before in any other path.
Cyclomatic Complexity calculate with flow graph
➢ cyclomatic complexity can be calculated with respect to
functions, modules , methods or classes with in a program.
➢ The cyclomatic complexity V(G) is said to be a metric for a
program's logical complexity.
▪ Three distinct formulas can be used to compute it :-
1. Formula based on edges and nodes :
▪ V(G) = e - n + 2 is a formula based on edges and nodes.
▪ Where e is the number of edges, and n denotes the number of
vertices.
2. Formula based on Decision Nodes :
➢ V(G) = P +1 where P number of predicate nodes (that contain conditions like
if and while condition statements. ).
Path Testing Cont.
3. Formula based on Regions :
▪ V(G) = number of regions in the graph
Example :
Method 2: Formula based on Decision
Nodes :
V(G) = d + P
where, d = 1 and p = 1 So,
Cyclomatic Complexity V(G) = 1 + 1 = 2
7. Testing for All-I-Uses : It refers to the All Input Uses. It verifies all
possible paths where a variable is obtained from external inputs.
10. Testing for Use-Definition Paths : It evaluates the path that leads to
the point where a variable is used and then defined.
Data Flow Testing Cont.
Advantages of Data Flow Testing
▪ Data Flow Testing is used to find the following issues:-
➢ To find a variable that is used but never defined,
➢ To find a variable that is defined but never used,
➢ To find a variable that is defined multiple times before it is use,
➢ Deallocating a variable before it is used.
Disadvantages of Data Flow Testing
➢ Time consuming and costly process
➢ Requires knowledge of programming languages
Data Flow Testing Cont.
Example 1
1. read x, y; Control flow graph of above example:
2. if(x>y)
3. a = x+1
else
4. a = y-1
5. print a;
2 3 4 5 10
Data Flow Testing Cont.
Assume at step 4 read 5 for y value and at step 8 read 0 for y value
then the control flow graph will be
2 6 7
3 8
4 9
5 10
Data Flow Testing Cont.
❖ Define use testing
➢ One of data flow testing techniques
➢ Use paths related to variable in CFG.
➢ variables are either define or used.
▪ Define use testing - define nodes
1. var x,y,sum 2 6 7
2. x=0
3. sum=0
4. read (y) 3 8
5. while (y!=0)
6. sum=sum+y
7. x=x+1 4 9
8. read(y)
9. end while
10. Print(“the sum of”+ x+” number is”+ sum)
5 10
Data Flow Testing Cont.
❖ Define use testing - use nodes
➢ P-use(predicate use ) (eg. Y!=0)
➢ C-use(computation use) (eg. For variable y: sum =sum+y)
✓ (O-use(output use ) .L-use ( Location use) or I-use( Iteration use))
1. var x,y,sum
2 6 7
2. x=0
3. sum=0
4. read (y)
3 8
5. while (y!=0)
6. sum=sum+y
7. x=x+1
4 9
8. read(y)
9. end while
10. Print(“the sum of”+ x+” number is”+ sum)
5 10
Data Flow Testing Cont.
▪ Define use node for variable x
1 var x,y,sum
2 x=0 Define
3 sum=0
4 read (y)
5 while (y!=0)
6 sum=sum+y
7 x=x+1 Define , use
8 read(y)
9 end while
10 Print(“the sum of”+ x+” number is”+ sum) Use
Data Flow Testing Cont.
▪ Define use node for variable y
1 var x,y,sum
2 x=0
3 sum=0
4 read (y) Define
5 while (y!=0) Use
6 sum=sum+y Use
7 x=x+1
8 read(y) Define
9 end while
10 Print(“the sum of”+ x+” number is”+ sum)
Data Flow Testing Cont.
▪ Define use node for variable sum
1 var x,y,sum
2 x=0
3 sum=0 Define
4 read (y)
5 while (y!=0)
6 sum=sum+y Define, Use
7 x=x+1
8 read(y)
9 end while
10 Print(“the sum of”+ x+” number is”+ sum) Use
Data Flow Testing Cont.
▪ define use test
➢ Select a set of path and test them to find anomalies (bugs)
➢ all path (too many !),all edges and nodes
➢ DU paths(define use paths)
➢ DC Paths(Define Clear paths)
▪ In define use testing , there are 6 data flow testing metrics
Data Flow Testing Cont.
▪ Program slices
➢ one of data flow testing techniques
➢ a set of statements using which the variable value is
computed
➢ slice can be up to any point in the program.
Data Flow Testing Cont.
▪ Slices for variable x
1 var x,y,sum
2 x=0 S(x,2) {2}
3 sum=0
4 read (y)
5 while (y!=0)
6 sum=sum+y
7 x=x+1 S(x,7) {2,5,7,9}
8 read(y)
9 end while
10 Print(“the sum of”+ x+” number is”+ sum) S(x,10) {2,5,7,9}
Data Flow Testing Cont.
▪ Slices for variable y
1 var x,y,sum
2 x=0
3 sum=0
4 read (y) S(y,4) {4}
5 while (y!=0) S(y,5) {4,5,8,9}
6 sum=sum+y S(y,6) {4,5,8,9}
7 x=x+1
8 read(y) S(y,8) {8}
9 end while
10 Print(“the sum of”+ x+” number is”+ sum)
Data Flow Testing Cont.
▪ Slices for variable sum
1 var x,y,sum
2 x=0
3 sum=0 S(sum,3) {3}
4 read (y)
5 while (y!=0)
6 sum=sum+y S(sum,6) {3,4,5,6,8,9}
7 x=x+1
8 read(y)
9 end while
10 Print(“the sum of”+ x+” number is”+ sum) S(sum,10) {3,4,5,6,8,9}
Data Flow Testing Cont.
▪ Definition Use paths for variable x
1 var x,y,sum
3 sum=0
4 read (y)
5 while (y!=0)
6 sum=sum+y
9 end while
2 x=0
3 sum=0
7 x=x+1
9 end while
2 x=0
4 read (y)
5 while (y!=0)
7 x=x+1
8 read(y)
9 end while