INTRODUCTION
Testing is concerned with errors, faults, failures, and incidents. A test is the act of exercising software
with test cases. A test has two distinct goals namely, to find failures or to demonstrate correct execution.
A test case has an identity and is associated with program behavior. A test case also has a set of inputs
and a list of expected outputs. The essence of software testing is to determine a set of test cases for the
item to be Tested.
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 classifying as:
1. Specification-based Test Case Design Techniques: The specification-based test case design
techniques are used to design test cases based on an analysis of the description or model of the
product without reference to its internal workings. These techniques are also known as black-box test
case design techniques. These techniques leverage external description of software to test cases such
as Technical specifications, Designs, Client’s requirements and so on.
2. Structure-based Test Case Design Techniques: The structural test case design techniques 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 test case Design techniques. In these techniques the test cases are
designed based on internal design Software code, Internal structure, Design and so on.
3. Experience-based Techniques: Experience-based test case design technique Used to
complement black-box and white-box techniques. In experience-based test techniques,
people’s knowledge, skills and background are a prime contributor the test conditions,
test cases and test data. The experience of both technical and business people is
required, as they bring different perspectives to the test an and design process. Due to
previous experience with similar systems, they may have insights into what could go
wrong, which is very useful for testing, structural and behavioral insights are used to
design experience-based tests.
All experience-based test case design techniques have the common characteristics that
they are based on human knowledge and experience. Test cases are therefore derived in a
less systematic way, but may be more effective. Experience-based test case design
techniques are highly dependent on tester’s experience, Knowledge, Expertise and so on).
• White-box testing is a way of testing the external functionality of the code by examining
and testing the program code that realizes the external functionality. White-box testing is
also known as clear box or glass box or open box testing. White-box testing takes into
account the program code, code structure, and internal design flow.
• A number of defects come about because of incorrect translation of requirements and
design into program code. Some other defects are created by programming errors.
• White-box testing is further has two types namely, Static testing and Structural testing.
1. Static testing is a type of testing which requires only the source code of the product,
not the binaries or executables.
2. Structural testing takes into account the code, code structure, internal design, and How
they are coded.
• White-box testing verifies the designs and codes involved in the development of a
software product.
WRITE SIMPLE PROGRAMS MAKE USE OF LOOPS AND CONTROL STRUCTURES WITH
TEST CASES
Code coverage is a software testing metric or also termed as a Code Coverage Testing which helps in
determining how much code of the source is tested which helps in accessing quality of test suite and
analysing how comprehensively a software is verified. Actually in simple code coverage refers to the degree
of which the source code of the software code has been tested. This Code Coverage is considered as one of
the form of white box testing.
As we know at last of the development each client wants a quality software product as well as the developer
team is also responsible for delivering a quality software product to the customer/client. Where this quality
refers to the product’s performance, functionalities, behaviour, correctness, reliability, effectiveness,
security, and maintainability. Where Code Coverage metric helps in determining the performance and
quality aspects of any software.
Code Coverage testing is determining how much code is being tested. It can be calculated using the
formula:
Code Coverage = (Number of lines of code exercised)/(Total Number of lines of code) * 100%
Statement Coverage Testing
• Statement coverage is one of the widely used software testing. It comes under white box testing.
• Statement coverage technique is used to design white box test cases. This technique involves
execution of all statements of the source code at least once. It is used to calculate the total number of
executed statements in the source code out of total statements present in the source code.
• Statement coverage derives scenario of test cases under the white box testing process which is based
upon the structure of the code.
• In white box testing, concentration of the tester is on the working of internal source code and flow
chart or flow graph of the code.
• Generally, in the internal source code, there is a wide variety of elements like operators, methods,
arrays, looping, control statements, exception handlers, etc. Based on the input given to the program,
some code statements are executed and some may not be executed. The goal of statement coverage
technique is to cover all the possible executing statements and path lines in the code.
Let's understand the process of calculating statement coverage by an example:
Here, we are taking source code to create two different scenarios according to input values to check the percentage of
statement coverage for each scenario.
Source Code Structure:
• Take input of two values like a=0 and b=1.
• Find the sum of these two values.
• If the sum is greater than 0, then print "This is the positive result."
• If the sum is less than 0, then print "This is the negative result."
input (int a, int b)
{
function to print sum of these integer values (sum = a+b)
If (sum>0)
{
print (This is positive result)
} else
{
print (This is negative result)
}
}
So, this is the basic structure of the program, and that is the task it is going to do.
Now, let's see the two different scenarios and calculation of the percentage of Statement Coverage for given source code.
Scenario 1:
If a = 5, b = 4
1. print (int a, int b) {
2. int sum = a+b;
3. if (sum>0)
4. print ("This is a positive result")
5. else
6. print ("This is negative result")
7. }
In scenario 1, we can see the value of sum will be 9 that is greater than 0 and as per the condition result will be "This is a
positive result." The statements highlighted in yellow color are executed statements of this scenario.
To calculate statement coverage of the first scenario, take the total number of statements that is 7 and the number of used
statements that is 5.
Total number of statements = 7
Number of executed statements = 5
Statement coverage = 5/7*100
= 500/7
= 71%
Scenario 2:
If A = -2, B = -7
1. print (int a, int b) {
2. int sum = a+b;
3. if (sum>0)
4. print ("This is a positive result")
5. else
6. print ("This is negative result")
7. }
In scenario 2, we can see the value of sum will be -9 that is less than 0 and as per the condition, result will
be "This is a negative result." The statements highlighted in yellow color are executed statements of this
scenario.
To calculate statement coverage of the first scenario, take the total number of statements that is 7 and the
number of used statements that is 6.
Total number of statements = 7
Number of executed statements = 6
Statement coverage = 6/7*100
= 600/7
= 85%
But, we can see all the statements are covered in both scenario and we can consider that the overall statement
coverage is 100%.
So, the statement coverage technique covers dead code, unused code, and branches.
Decision Coverage Testing
Decision coverage technique comes under white box testing which gives decision coverage to
Boolean values. This technique reports true and false outcomes of Boolean expressions.
Whenever there is a possibility of two or more outcomes from the statements like do while
statement, if statement and case statement (Control flow statements), it is considered as
decision point because there are two outcomes either true or false.
Decision coverage covers all possible outcomes of each and every Boolean condition of the
code by using control flow graph or chart.
Generally, a decision point has two decision values one is true, and another is false that's why
most of the times the total number of outcomes is two. The percent of decision coverage can be
found by dividing the number of exercised outcome with the total number of outcomes and
multiplied by 100.
In this technique, it is tough to get 100% coverage because sometimes expressions get
complicated. Due to this, there are several different methods to report decision coverage. All
these methods cover the most important combinations and very much similar to decision
coverage. The benefit of these methods is enhancement of the sensitivity of control flow.
We can find the number of decision coverage as follows.
Let's understand it by an example.
Consider the code to apply on decision coverage technique:
1. Test (int a)
2. {
3. If(a>4)
4. a=a*3
5. Print (a)
6. }
Scenario 1:
Value of a is 7 (a=7)
1. Test (int a=7)
2. { if (a>4)
3. a=a*3
4. print (a)
5. }
The code highlighted in yellow is executed code. The outcome of this code is "True" if
condition (a>4) is checked.
Control flow graph when the value of a is 7.
Calculation of Decision Coverage percent:
1. Decision Coverage = ½*100 (Only "True" is exercised)
2. =100/2
3. = 50
4. Decision Coverage is 50%
Scenario 2:
Value of a is 3 (a=3)
1. Test (int a=3)
2. { if (a>4)
3. a=a*3
4. print (a)
5. }
The code highlighted in yellow will be executed. The outcome of this code is ?False? if
condition (a>4) is checked.
Control flow graph when the value of a is 3
1. = ½*100 (Only "False" is exercised
2. =100/2
3. = 50
4. Decision Coverage = 50%
Result table of Decision Coverage:
Decision
Test Case Value of A Output
Coverage
1 3 3 50%
2 7 21 50%
Branch Coverage Testing
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 Whitebox testing technique that ensures that every branch of each
decision point must be executed.
However, 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.
X 100
How to calculate Branch coverage?
There are several methods to calculate Branch coverage, but pathfinding is the most common method.
In this method, the number of paths of executed branches is used to calculate Branch coverage. Branch
coverage technique can be used as the alternative of decision coverage. Somewhere, it is not defined as
an individual technique, but it is distinct from decision coverage and essential to test all branches of the
control flow graph.
Let's understand it with an example:
Read X
Read Y
IF X+Y > 100 THEN
Print "Large"
ENDIF
If X + Y<100 THEN
Print "Small"
ENDIF
This is the basic code structure where we took two variables X and Y and two conditions. If the first
condition is true, then print "Large" and if it is false, then go to the next condition. If the second
condition is true, then print "Small."
Control flow graph of code structure
In the above diagram, control flow graph of code is depicted. In the first case traversing
through "Yes "decision, the path is A1-B2-C4-D6-E8, and the number of covered edges is
1, 2, 4, 5, 6 and 8 but edges 3 and 7 are not covered in this path. To cover these edges, we
have to traverse through "No" decision. In the case of "No" decision the path is A1-B3-5-
D7, and the number of covered edges is 3 and 7. So by traveling through these two paths,
all branches have covered.
Path 1 - A1-B2-C4-D6-E8
Path 2 - A1-B3-5-D7
Branch Coverage (BC) = Number of paths
=2
Case Covered Branches Path Branch coverage
Yes 1, 2, 4, 5, 6, 8 A1-B2-C4-D6-E8
2
No 3,5,7 A1-B3-5-D7
Branch Coverage for result Yes:
Branch coverage=5/8*100=62.5%
Covered Branches(Conditional +
Case Path Branch Coverage
Unconditional)
Branch Coverage for result No:
Yes Branch coverage=3/8*100=37.5%
1, 2, 4, 5, 6, 8 A1-B2-C4-D6-E8 75%
No 3,5,7 A1-B3-5-D7 37.5%
Advantages of Branch coverage:
1. Allows you to validate-all the branches in the code
2. Helps you to ensure that no branched lead to any abnormality of the program’s operation
3. Branch coverage method removes issues which happen because of statement coverage
testing.
4. Allows you to find those areas which are not tested by other testing methods.
5. It allows you to find a quantitative measure of code coverage.
6. Branch coverage ignores branches inside the Boolean expressions.
Consider the Following Code.
1. Read a
2. If(a>5)
3. a=a*3
4. end if
5. print(a)
Loop Software Testing
Loop Testing is a type of software testing type that is performed to validate the loops. It is one
of the type of Control Structure Testing. Loop testing is a white box testing technique and is
used to test loops in the program.
Objectives of Loop Testing:
The objective of Loop Testing is:
• 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:
Loop testing is classified on the basis of the types of the loops:
[Link] Loop Testing:
Testing performed in a simple loop is known as 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 and false occurrence of the condition respectively. This type of
testing is performed basically to test the condition of the loop whether the condition is
sufficient to terminate loop after some point of time.
Example:
while(condition)
{
statement(s);
}
[Link] Loop Testing:
Testing performed in a nested loop in known as Nested loop testing. Nested loop is basically
one loop inside the another loop. In nested loop there can be finite number of loops inside a
loop and there a nest is made. It may be either of any of three loops i.e., for, while or do-while.
Example:
while(condition 1)
{
while(condition 2)
{
statement(s);
}
}
[Link] Loop Testing:
Testing performed in a concatenated loop is known as Concatenated loop testing. It is performed
on the concatenated loops. Concatenated loops are loops after the loop. It is a series of loops.
Difference between nested and concatenated is that in nested loop is inside the loop but here loop
is after the loop.
Example:
while(condition 1)
{
statement(s);
}
while(condition 2)
{
statement(s);
}
[Link] Loop Testing:
Testing performed in an unstructured loop is known as Unstructured loop testing.
Unstructured loop is the combination of nested and concatenated loops. It is basically a group
of loops that are in no order.
Example:
while()
{
for()
{}
while()
{}
}
Advantages of Loop Testing:
• Loop testing limits the number of iterations of loop.
• Loop testing ensures that program doesn’t go into infinite loop process.
• Loop testing endures initialization of every used variable inside the loop.
• Loop testing helps in identification of different problems inside the loop.
• Loop testing helps in determination of capacity.
Disadvantages of Loop Testing:
• Loop testing is mostly effective in bug detection in low-level software.
• Loop testing is not useful in bug detection.
#include<stdio.h>
int main()
{
int i=1,n;
printf("\nEnter n::");
scanf("%d",&n);
while(i<=n)
{
printf("%d\n",i);
i++;
}
return 0;
}
Loop Test Case n Output
Coverage
While(i<=n) 1 4 1
2
3
4
2 6 1
2
3
4
5
6
3 -2 No output
4 0 No output
Path testing
Path testing is a structural testing method that involves using the source code of a program
in order to find every possible executable path. It helps to determine all faults lying within a
piece of code. This method is designed to execute all or selected path through a computer
program.
Any software program includes, multiple entry and exit points. Testing each of these points
is a challenging as well as time-consuming. In order to reduce the redundant tests and to
achieve maximum test coverage, basis path testing is used.
Path Testing is a White Box Testing method in which test cases are defined based on flows
or logical paths that can be taken through the program. The objective of basis path testing is
to define the number of independent paths, so the number of test cases needed can be
defined explicitly to maximize test coverage.
Advantages of Path Testing
1. It helps to reduce the redundant tests.
2. It focuses attention on program logic.
3. Test cases which exercise basis set will execute every statement in a program at least once.