Unit 2 covers white box testing techniques including control flow testing and data flow testing. Control flow testing aims to execute all statements, branches, and paths in the code. Different coverage criteria like statement coverage and branch coverage are discussed. Data flow testing checks for data flow anomalies like variables being defined but not used or used but not defined. A data flow graph example is provided to illustrate data flow terminologies like all-c-uses criterion. Advantages of white box testing include thorough testing of all code paths while disadvantages include complexity, time consumption, and requiring specialized resources.
2. Contents
• Overview of white box testing
• Control flow testing
• Process of generating test input data : Example
• Various coverage criterias
• Dataflow testing
• Data flow anomalies
• Data flow graph
• Data flow terminologies
3. Overview of white box testing
• The testers require knowledge of how the software is implemented, the tester is concentrating
on how the software does it. For example, a structural technique may be concerned with
exercising loops in the software.
• WHITE BOX TESTING is testing of a software solution's internal structure, design, and
coding. In this type of testing, the code is visible to the tester.
• It focuses primarily on verifying the flow of inputs and outputs through the application,
improving design and usability, strengthening security.
• Performs to check/verify
• Internal security holes
• Broken or poorly structured paths in the coding processes
• The flow of specific inputs through the code
• Expected output
• The functionality of conditional loops
• Testing of each statement, object, and function on an individual basis
4. Example
Printme (int a, int b)
{
int result = a+ b;
If (result> 0)
Print ("Positive", result)
Else
Print ("Negative", result)
}
“The goal of White Box testing is to verify
all the decision branches, loops, statements
in the code.”
Advantages of White Box Testing
• Code optimization by finding hidden
errors.
• White box tests cases can be easily
automated.
• Testing is more thorough as all code
paths are usually covered.
• Testing can start early in SDLC even if
GUI is not available.
Disadvantages of White Box Testing
• White box testing can be quite complex and expensive.
• The white box testing by developers is not detailed can lead to
production errors.
• White box testing requires professional resources, with a
detailed understanding of programming and implementation.
• White-box testing is time-consuming, bigger programming
applications take the time to test fully.
6. Statement Coverage
• This technique requires every possible
statement in the code to be tested at least
once during the testing process.
• Statement coverage =( number of statement
executed/total number of statements )
1.Printme (int a, int b){
2. int result = a+ b;
3. If (result> 0)
4. Print ("Positive", result)
5. Else
6. Print ("Negative", result)
7.}
Scenario 1:
A= 5 B= 6;
The statements marked in red colour are those which are
executed as per the scenario
Number of executed statements = 5,
Total number of statements = 7
Statement Coverage: 5/7 = 71%
What is covered by Statement Coverage?
Unused Statements
Dead Code
Unused Branches
Missing Statements
7. Branch Coverage vs Decision coverage
• This technique requires every possible branch in
the code to be tested at least once during the
testing process.
• Branch coverage=(number of branches
executed/total number of branches)
What is covered by Branch Coverage?
Allows you to validate-all the branches in the code
Helps you to ensure that no branched lead to any abnormality
of the program's operation
Branch coverage method removes issues which happen
because of statement coverage testing
Allows you to find those areas which are not tested by other
testing methods
It allows you to find a quantitative measure of code coverage
Branch coverage ignores branches inside the Boolean
expressions
TestValueofX(int x)
{
if (x>9)
print x;
print (x+6);
}
Test
Case
Value of
X
Output Branch
Coverage
1 8 14 67%
2 10 10 ,16 100%
8. • Reports true or false outcomes of each Boolean expression. In
this coverage, expressions can sometimes get complicated.
Therefore, it is very hard to achieve 100% coverage.
Test case 1
• Number of executed decision = 1,
• Total number of decisions = 2
Test case 2
• Number of executed decision = 1,
• Total number of decisions = 2
TestValueofX(int x)
{
if (x>9)
print x;
else
print (x+6);
}
Test
Case
Value of
X
Output Decision
Coverage
1 8 14 50%
2 10 10 50%
Branch Coverage vs Decision coverage
10. Data Flow Anomalies
• Defined and Then Defined Again
• Example: int x=10;
int x=12; // In same source code
• Undefined but Referenced
• Example: x=10; // In source code is undefined
• Defined but Not Referenced
• Example: int x; // In source code , x is defined but not referenced.
13. Data Flow Terminologies and C-use(ti) variable
all-c-uses criterion with respect to variable ti
Paths should be 1-2-3-4-5-6-3-7-8-10, 1-2-3-4-5-6-3-7-9-10, 1-2-3-4-6-3-7-8-10, and 1-2-3-4-6-3-7-9-10.