TestingTools_Chap2
TestingTools_Chap2
• Commonly used code coverage testing techniques are Statement Coverage testing,
Decision Coverage Testing, Branch Coverage testing, Loop Coverage testing &
Path Coverage testing.
Statement Coverage Testing:
• It is simplest form of white-box testing, whereby a series of test cases are run such that
each statement is executed at least once.
• Statement coverage testing’s achievement is insufficient to provide confidence in a
software product’s behaviour.
• A weakness of statement coverage testing is that there is no guarantee that all outcomes of
branches are properly tested.
• Ex: def check_discount(amount):
if amount > 100:
print("You get a 10% discount!")
else:
print("No discount available.")
check_discount (150)
Case 1: Case 2:
If A=7 , B =3 If A=4, B=8
No. of statements executed = 5 No. of statements executed = 6
Total Statements = 7 Total Statements = 7
Statement Coverage = 5/7 *100 Statement Coverage = 6/7 *100
= 71.00 % = 85.20 %
Why is statement coverage used?
• To check the quality of the code.
• To determine the flow of different paths of the program.
• Check whether the source code expected to perform is valid or not.
• Tests the software’s internal coding and infrastructure.
Test Case 1 :
Value of x is 9 ( x= 9) The outcome of this code is “True” if condition (x>5) is c
Test (int x=9) checked.
{
if (x >5)
x = x *3
print (x)
}
Calculation of Decision Coverage percentage: FlowChart
• It is improvement over statement coverage, in that a series of tests are run to ensure
that all branches are tested at least once.
• Branch Coverage is also sometimes referred to as all edge coverage.
• It requires sufficient test cases for each program decision or branch to be executed
so that each possible outcome occurs at least once.
• The purpose of branch coverage testing is to ensure that each decision condition
from every branch is executed at least once.
• Branch Coverage Technique is used to cover all branches of the control flow graph.
It covers all possible outcomes of each condition point at least once.
• Branch coverage technique and decision coverage technique are similar, but there
is a key difference between the two,
• Decision Coverage : Ensures all decision points (if, switch) are evaluated for both
TRUE and FALSE.
• Branch Coverage : Ensures every possible branch (true and false) from each
decision point is executed.
Ex: def check_number(n): Decision Coverage test cases:
if n > 0: check_number = 5
print("Positive") check_number = -5
else:
print("Negative or Zero") Branch Coverage test cases :
check_number = 5
check_number = -5
check_number = 0
Read A
Read B
If A + B THEN
Print “Larger than 100”
ENDIF
If A +B > 50 THEN
Print “Larger than 50”
ENDIF
Path 1 : P1-Q2-R4-5-S6-T8
Path 2 : P1-Q3-5-S7
Branch Coverage = Number of paths =2
Ex:
while (condition 1)
{
while (condition 2)
{
// Statement (s)
}
}
3. Concatenated Loop Testing:
• Testing applied on a concatenated loop is recognized as concantenated loop testing.
Concatented loops are loops after the loops.
• Nested loops means loop inside a loop and concantenated means loop is after the
loop.
Path:
• A path through a program is a node and edge sequence from the starting node to a
terminal node of the control flow graph of a program.
• There can be more than one terminal node in a program.
• Writing test cases to cover all the paths of a typical program is impractical.
Linearly Independent Path :
• Linearly Independent path is any path through the program that introduces at least
one new edge that is not included in any other linearly independent paths.
• If a path has one new node compared to all other linearly independent paths, then
the path is also linearly independent.
• This is because any path having a new node automatically implies that it has a new
edge.