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

TestingTools_Chap2

Chapter 2 discusses test case design techniques for software, categorizing them into specification-based, structure-based, and experience-based methods. It elaborates on various white-box testing techniques, including Statement Coverage, Decision Coverage, Branch Coverage, Loop Coverage, and Path Coverage, explaining their purposes, advantages, and disadvantages. The chapter emphasizes the importance of code coverage in ensuring comprehensive testing of software functionalities.

Uploaded by

aniljagdale2004
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)
7 views

TestingTools_Chap2

Chapter 2 discusses test case design techniques for software, categorizing them into specification-based, structure-based, and experience-based methods. It elaborates on various white-box testing techniques, including Statement Coverage, Decision Coverage, Branch Coverage, Loop Coverage, and Path Coverage, explaining their purposes, advantages, and disadvantages. The chapter emphasizes the importance of code coverage in ensuring comprehensive testing of software functionalities.

Uploaded by

aniljagdale2004
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/ 25

Chapter-2

Test Cases for Simple Programs


The main goal of test case design techniques is to test the functionalities and features
of software with the help of effective test cases.
The test case design techniques are broadly classifies as:
1. Specification-based Test Case Design Techniques: This are used to design test
cases based on an analysis of the description or model of the product without
reference to its internal working. It is also known as Black-box testing.
2. Structure-based Test Case Design Techniques: This are used to design test
cases based on an analysis of the internal structure of the test item. These
techniques are also known as white-box testing.
3. Experience-based Techniques: This are used to complement black-box and
white-box techniques. In experience based test techniques people’s knowledge,
skills and background are a prime contributor to the test conditions, test cases and
test data. The experience of both technical and business is required, as they bring
different prespective to the test analysis and design process. Due to previous with
similar system, they may have insights into what could go wrong, which is very
useful for testing.
• The percentage of program statements that can be invoked during this phase of
testing is called “Code Coverage”.
• Code Coverage is white-box testing because it requires us to have full access to
the code of view what parts of the software we pass through when we run the test
and what parts of the software fail.
• The primary purpose of code coverage testing is to ensure that the testing activity
covers as much code as possible.
• Code Coverage testing is a technique that involves measuring the percentage of a
system’s code that is being tested by a test suite.

Code Coverage = No. of lines of code exercised


X 100
Total no. of lines of the code

• 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)

(It will not check the else condition)


• Statement Coverage is used for calculation of the number of statements in source
code which have been executed.
• The main purpose of Statement Coverage is to cover all the possible paths, lines
and statements in source code.

Number of executed statements


Statement Coverage = X 100
Total Number of statements
Example:
Read A
Read B
if A > B
Print “A is greater than B”
else
Print “B is greater than A”
endif

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.

Drawback of Statement Coverage:


• Cannot check the false condition.
• Different input values to check all the conditions.
• More than one test case may be required to cover all the paths with a coverage of
100%.
Decision Coverage testing:
• It is white-box testing technique which reports the True or false outcomes of each
Boolean expression of the source code.
• Decision coverage testing criteria requires sufficient test cases for each condition in
a program decision to take on all possible outcomes at least once.
• The goal of decision coverage testing is to cover and validate all the accessible
source code by checking and ensuring that each branch of every possible point is
executed at least once.

Number of decision outcomes exercised


Decision Coverage = X 100
Total number of decision outcomes
Example:
test (int x)
{
if ( x> 5)
x=x*3
print (x)
}

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

Decision Coverage = 1 / 2 * 100 (only true)


= 50 %
Advantage of Decision Coverage:
• Validate that all branches in the code are reached.
• Ensure that no branches lead to any abnormality of the program’s operation.
• It eliminates problems that occur with statement coverage testing.

Disadvantages of Decision Coverage:


• This metric ignores branches within Boolean expressions which occur due to short-
circuit operators.
Branch Coverage Testing:

• 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

Branch Coverage = 5/8 *100 = 62.5 % (for yes)


Branch Coverage = 3/8 *100 = 37.5% (for No)
Advantages of Branch Coverage :
• It allows to validate-all the branches in the code.
• It helps to ensure that no branched lead to any abnormality of the program’s
operation.
• Branch coverage method removes issue which happen because of statement
coverage testing.

Disadvantages of Branch Coverage:


• It is costly.
• It takes more time for performing this task.
Loop Coverage Testing:
• Loop coverage testing criteria requires sufficient test cases for all programs loops
to be executed for zero, one, two and many iteration covering initialization, typical
running and termination conditions.
• It is type of white box testing technique to validate the loops. It is one of the type
of control structure testing.
• It is a test coverage criteria which checks whether loop body executed zero time,
exactly once or more than once.
• The goals of loop coverage testing are:
• To fix the infinite loop repetition problem.
• To know the performance.
• To identify the loop initialization problems.
• To determine the uninitialized variables
Types of Loop Testing:

1. Simple Loop Testing:


• Simple Loop is basically a normal “for” , “while” or “do-while” in which a
condition is given and loop runs and terminates according to True or False
occurrence of the condition respectively.
Ex.
while (condition)
{
// statement (s)
}
2. Nested Loop Testing:
• In nested loop there can be finite number of loops inside a loop and there a nest is
made. It mau be either of any of three loops i.e., for, while or do-while.

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.

Ex: while (condition 1)


{
// statement (s)
}
while (condition 2)
{
// statement (s)
}
4. Unstructured Loop Testing:
• Testing applied on an unstructured loop is known as unstructured loop testing.
• It is combination of concatenated and nested loops.
• In other words, it is group of loops that are in no particular order.
Ex. :
while ( )
{
for()
{
}
while()
{
}
}
Path Coverage Testing:
• The path coverage-based testing strategy requires us to design test cases such that
all linearly independent paths in the program are executed at least once.
• A linearly independent path can be defined in terms of the Control Flow Graph of a
program. A CFG describes how the control flows through the program.

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.

Total Path Exercised


Path Coverage = X 100
Total Number of paths in the program
Ex: def check_number(x):
if x > 0:
print("Positive")
else:
if x == 0:
print("Zero")
else:
print("Negative")

You might also like