ST_Unit2
ST_Unit2
Testing
(UNIT 2)
White Box Testing -Introduction
White box testing is a software testing technique that involves
testing the internal structure and workings of a software
application .
The tester has access to the source code and uses this knowledge to
design test cases that can verify the correctness of the software at
the code level.
It is also called glass box testing clear box testing or structural
testing. White Box Testing is also known as transparent testing or
open box testing.
White box testing is also known as structural testing or code-based
testing, and it is used to test the software’s internal logic, flow, and
structure. The tester creates test cases to examine the code paths
and logic flows to ensure they meet the specified requirements.
White Box Testing -Introduction
Reasons for white box testing:
It identifies internal security holes.
To check the way of input inside the code.
Check the functionality of conditional loops.
To test function, object, and statement at an individual level.
The term 'white box' is used because of the internal perspective of the
system.
The clear box or white box or transparent box name denote the ability
to see through the software's outer shell into its inner workings.
White Box Testing -Introduction
White Box Testing -Introduction
Here’s an example demonstrating how white box testing works :
def Printme(a, b):
result = a + b
if result > 0:
print("Positive", result)
else:
print("Negative", result)
In this code, Printme is a function that takes two inputs, adds them,
and checks whether the result is positive or negative. If the result is
positive, it prints “Positive”. If the result is not positive (i.e., zero or
negative), it prints “Negative” along with it.
White Box Testing -Introduction
The goal of White Box Testing here is to verify all the decision
branches (the if-else condition) in the code.
Test Case 1: a = 1, b = 1
This would test the “Positive” branch of the if-else condition.
Test Case 2: a = -1, b = -3
This would test the “Negative” branch of the if-else condition.
White Box Testing –Real Life Examples
Google employs white box testing extensively across its products
and services, including Google Search, Gmail, and Google Cloud
Platform.
For instance, white box testing in Google Search ensures that search
algorithms operate efficiently and deliver accurate results based on
complex ranking criteria.
Amazon rigorously applies white box testing to its e-commerce
platform, AWS cloud services, and Kindle devices.
For example, in AWS, white box testing ensures that cloud services
operate reliably, handle data securely, and scale efficiently for
millions of customers globally.
White Box Testing -Types
Unit Testing
Dynamic Testing
Static Analysis
Decision Testing
Data Flow Testing
Types Of White Box Testing - Unit Testing
Imagine you’re building a bicycle. Unit testing would be like checking
each part separately – testing the brakes, the gears, the pedals, etc.,
to ensure they all work correctly before assembling the whole bicycle.
Unit testing is a white box testing method where you check individual
units of source code.
Developers write those tests to check only the functionality of a
small part of an application at a time.
Checks if each part or function of the application works correctly.
Ensures the application meets design requirements during
development.
Types Of White Box Testing - Unit Testing
Programmers are primarily responsible for unit testing.
Software developers write a few lines of code, a single function or
object, test it to ensure it works, and then move on to the next step.
In the early stages of the software development lifecycle, unit tests
help identify most problems.
Errors discovered at this stage are inexpensive and easy to fix.
JUnit is a Java framework that facilitates unit testing by allowing
developers to define test cases, execute them, and assert expected
outcomes, promoting code reliability through automated testing
practices.
Types Of White Box Testing - Dynamic Testing
This would be like test-driving a car. You’re not just looking at the
components (like in static analysis), but you’re driving the car to see
how it performs on the road.
Dynamic testing is a type of software testing that involves executing
the software and evaluating its behavior during runtime.
It is also known as functional testing, as it focuses on testing the
software’s functionality and how it behaves under different inputs and
conditions.
Types Of White Box Testing - Static Analysis
This is like proofreading a book before it’s published. You’re looking
for errors in grammar, punctuation, and sentence structure. Still, you
need to read the book as a whole to understand the story (which
would be more like dynamic analysis).
Static analysis involves reviewing and analyzing code without
executing it.
You can use tools to inspect source code, identify potential defects,
enforce coding standards, and detect vulnerabilities early in
development
Example: Tools like Pylint for Python can be used to analyze the
is_prime function for code quality issues, such as naming conventions,
complexity, or even potential bugs.
Types Of White Box Testing - Decision Testing
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.
Types Of White Box Testing - Decision Testing
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.
Test (int a)
{
If(a>4)
a=a*3
Print (a)
}
Types Of White Box Testing - Decision Testing
Types Of White Box Testing - Decision Testing
Types Of White Box Testing - Decision Testing
Types Of White Box Testing - Data Flow Testing
Data flow testing is a white-box testing technique that examines
the data flow with respect to the variables used in the code.
It examines the initialization of variables and checks their values at
each instance.
There are two types of data flow testing:
Static data flow testing: The declaration, usage, and deletion of the
variables are examined without executing the code. A control flow
graph is helpful in this.
Dynamic data flow testing: The variables and data flow are examined
with the execution of the code.
Types Of White Box Testing - Data Flow Testing
Types Of White Box Testing - Data Flow Testing
White Box Testing Techniques
1) Statement Coverage
2) Path Testing
3) Branch Coverage
4) Loop Testing
5) Conditional Coverage
White Box Testing Techniques – Statement
Coverage
This is like making sure you read every sentence in a book.
In this technique, the aim is to traverse all statements at least once.
A statement refers to a line of code in the software which performs
some action.
Statement coverage refers to the percentage of statements covered
by white box testing out of the total statements.
If all the statements in the program have been executed by a set of
tests, then it is said that 100% statement coverage has been achieved.
However, if only half of the statements are executed then it is said
that 50% statement coverage has been achieved.
White Box Testing Techniques – Statement
Coverage
Statement coverage percentage is calculated as :
Case 2 :
White Box Testing Techniques – Statement
Coverage
Statement coverage covers:
Dead code.
Unused statements.
Unused branches.
Missing statements.
The project team has to take decision on the statement coverage
goal for every project.
White Box Testing Techniques –Path Testing
This is like reading a book’s possible combination of chapters. In code,
it means testing every possible path through the code from start to
finish.
It ensures that every potential path is executed at least once,
uncovering hidden bugs that might only emerge under specific
conditions.
Path Testing is a method that is used to design the test cases.
In the path testing method, the control flow graph (CFG) of a
program is designed to find a set of linearly independent paths of
execution.
Example: For the is_prime function, path testing involves creating
test cases that cover all paths through the function: checking numbers
less than or equal to 1, prime numbers, and non-prime numbers.
White Box Testing Techniques –Path Testing
A Control Flow Graph (CFG) is a graphical representation of all the
paths that might be traversed through a program during its
execution.
A control flow graph has 3 major components:
1. Node: these are individual statements or blocks of code. For
example, in the code snippet below we have 3 nodes:
int a = 0; // Node 1
if (b > 0) { // Node 2
a = b; // Node 3
}
White Box Testing Techniques –Path Testing
2. Edge: this is the flow of control from one node to another. It
indicates the execution flow of the program. There are 2 types of
edges:
Unconditional edge: direct flow from one statement to another
without any condition
Conditional edge: these are branches based on a condition (e.g.
True/False outcomes of an if-statement)
Here we have a conditional edge from statement ‘if (b > 0)’ to
statement ‘a=b’.
int a = 0;
if (b > 0) {
a = b;
}
White Box Testing Techniques –Path Testing
3. Entry/Exit Points: these represent the start and end of a program
in the CFG
Let’s look at another example.
void exampleFunction(int x, int y)
{
if (x > 0)
{
if (y > 0)
printf("Both x and y are positive.\n");
else
printf("x is positive, y is non-positive.\n");
}
else
printf("x is non-positive.\n");
}
White Box Testing Techniques –Path Testing
Here we have:
With decision table testing, you must test your system’s behavior
according to the multiple inputs. This total procedure will be
captured in the form of a table.
That means the table shows the inputs and their respective outputs.
A loan amortization table is a practical example of decision table
testing. You must enter the inputs – year (annual)/ month (monthly),
total interest, and principal amount within your online loan EMI
calculator.
The calculator will present these inputs and their corresponding
outputs (outstanding balances) in a tabular format.
Grey Box Testing Techniques – State Transition
Testing
State transition testing checks the behavior of an application when it
goes through different states and transitions.
A state indicates a condition or set of conditions under which you
must perform the testing.
The transition indicates the change from one condition to another
condition.
This testing aims to identify whether the system behaves as expected
within all the possible states and transitions.
So, you must prepare the test cases to verify the states and check the
transitions are happening without any bottleneck.
Grey Box Testing -Techniques
For example, when you pay any bill through your mobile banking
application, you have to test the following states –
Verifying your bill details and the biller’s name
Initializing the payment with the ‘Proceed to pay’ button’
Choosing a payment method
Entering security credentials (PIN/ CVV number, etc.)
Payment confirmation
So, the transition path will be –
Verifying bill and the details of the biller> initializing payment >
choosing payment method > entering security credentials > payment
confirmation.
Grey Box Testing - Advantages
Clarity of goals: It helps in keeping testers and developers separate,
which reduces any disagreement between them.
Done from user perspective: Gray box testing is mostly done by the
user perspective.
High programming skills not required: Testers are not required to
have high programming skills for this testing.
Non-intrusive: Gray box testing is non-intrusive as it is based on
functional specification, architectural view whereas not on source
code or binaries which makes it invasive too.
Improved product quality: Overall quality of the product is improved.
Instant Fixing: It results in the instant fixing of the issues as a tester
can change the partially available code to check for the results.
Grey Box Testing - Advantages
Defect fixing: In gray box testing, developers have more time for
defect fixing.
Benefits of black box and white box testing: By doing gray box
testing, benefits of both black box and white box testing is obtained.
Unbiased: Gray box testing is unbiased. It avoids conflicts between a
tester and a developer.
Effective testing: Gray box testing is much more effective in
integration testing.
Grey Box Testing - Disadvantages
Difficulty in defect association: Defect association is difficult when
gray testing is performed for distributed systems.
Limited access to internal structure: Limited access to internal
structure leads to limited access for code path traversal.
Source code not accessible: While doing grey box testing, testers do
not have access to the source code, so it becomes difficult to get
complete code path coverage and testers might fail to notice some
critical vulnerabilities.
Not suitable for algorithm testing: Gray box testing is not suitable for
algorithm testing as accessing the complete logic of the algorithms is
not possible.
It is usually not suitable for distributed systems.
White box V/s Grey Box Testing