What is White Box Testing and its Types with Examples?

White Box Testing

The box testing approach of Software Testing consists of Black Box Testing and White Box Testing and here in this article, we will learn White Box Testing and the following topics.

What is White Box Testing?

White Box

White Box Testing is a software testing technique that is based on the application’s internal code structure. In white-box testing, an internal perspective of the system, as well as programming skills, are used to design test cases. This testing usually is done at the unit level.

Here testers can see the code of the application under test.

It is also called as Glass Box Testing, Clear Box Testing, Open Box Testing, Transparent Box Testing, Code-Based Testing, Logic-Coverage Testing, Logic Driven Testing, Path Driven Testing, and Structural Testing, Structure-Based Testing.

These names represent the capability to see through the software’s outer shell (i.e., box) into its inner workings.

In this testing, testers must have knowledge of the internal structure, design, code of the application under test to verify input-output flow and to improve the design, security, and usability.

Box testing has two parts namely Black Box Testing & White Box Testing.

Check out our detailed guide on Black Box Testing vs White Box Testing.

Testers need to have good programming skills to derive the test cases for white box testing. It is a contract to its counterpart black box testing which derives test cases from its specifications.

ISTQB Definition of White Box Testing

As per the ISTQB glossary, the definition of White Box Testing is as follows

Testing based on an analysis of the internal structure of the component or system.

If the tester has code-level knowledge of the system or system component being tested then it’s possible for the tester to gain a deep understanding of the system.

White Box Testing Process

White Box Testing Process

Step 1: Gather requirements, functional specifications, design documents, source code.

Step 2: Testing plan preparation

Step 3: Test case preparation

Step 4: Test case execution

Step 5: Defect Reporting & fixing issues

Types of White Box Testing

Types of White Box Testing

The types of white box testing are as follows

Eventhough white box testing can be applied to unit testing, integration testing and system testing. It is advisable to stick with just Unit testing level and Integration testing level. 

  1. Unit Testing – Check detailed Unit Testing Guide
  2. Integration Testing – Check detailed Integration Testing Guide

Unit Testing is divided into Execution Testing, Operations Testing, and Mutation Testing. 

Integration Testing is divided into Top Down Approach, Bottom Up Approach, and Hybrid Approach.

Execution Testing is divided into Statement Coverage, Branch Coverage, and Path Coverage

Execution Testing:

It is a white box testing type that is to test the code and compare the actual output with the expected output.

Operations Testing:

It is a white box testing type that is to test the non-functional attributes such as perfromance, load, usability, security etc., of the unit module.

Mutation Testing:

It is a white box testing type that is to change (mutate) certain statements in the source code and verify if the tests are able to find the errors.

White Box Testing Techniques

Coverage Techniques

The important WhiteBox Testing Techniques are as follows

Statement Coverage:

This technique is used to make sure that each line of source code has been executed and tested at least once. Covering all lines of code points out the buggy code.

It is to calculate the total number of statements executed, out of the total number of statements executable in the source code.

Statement Coverage = (Number of statements executed / Total number of statements executable ) x 100%

As per the below flow chart, in statement coverage, every node must be traversed at least once.

Decision Coverage

It ensures that every decision (true/false) in the source code has been executed and tested.

Branch Coverage

This technique is used to make sure that all branches are tested at least once. It verifies every possible (if-else and other conditional loops) path of an application.

It ensures that each branch from all decision points is traversed at least once.

As per the flowchart, all edges must be traversed at least once.

Branch Coverage = (Number of decisions outcomes tested / Total number of decision outcomes ) x 100%

Path Coverage

This technique is used to ensure that every possible path (each statement and branch) is executed and tested.

Path Coverage = (Number of paths executed / Total number of paths) x 100%

Apart from the above there are many other coverage types as follows.

  • Condition Coverage
  • Multiple Condition Coverage
  • Finite State Machine Coverage
  • Control flow testing
  • Data flow testing

Don’t miss: 100+ Types of Software Testing

How To Calculate Statement Coverage, Branch Coverage, Path Coverage

First let’s learn what are nodes and edges

Nodes: Nodes represent entries, each statement of the code, decisions, and exits

Edges: Edges represent branching, and non-branching links between nodes.

Let’s take a sample program and calculate the statement coverage, branch coverage, and path coverage.

Read X
Read Y
IF X+Y > 100 THEN
Print “Greater”
ENDIF
If P > 50 THEN
Print “X>50”
ENDIF

Solution:

Here is the flow chart for the above program

Flow Chart

Let’s specify nodes and edges of above flow chart

Flow Chart With Nodes And Edges

Statement Coverage

It is to find the shortest number of paths by covering all the nodes.

With this one path 1A-2C-3D-E-4G-5H, we have covered all the nodes such as 1,2,3,4,5

Total number of statements covered are 1.

Branch Coverage

It is to find the minimum number of paths by covering all the edges. Here our focus is to cover all the possible true and false decisions.

With this path 1A-2C-3D-E-4G-5H, we have covered edges A,C,D,E,G, and H but we missed edges B and F.
With this path 1A-2B-E-4F, we have coverd edges A,B,E, and F.

By combining the above two paths we have covered all the edges A,B,C,D,E,F,G, and H.

Total number of branches covered are 2.

Path Coverage

It ensures covering all the possible paths right from start to end

1A-2B-E-4G-5H
1A-2B-E-4F
1A-2C-3D-E-4G-5H
1A-2C-3D-E-4F

Total number of paths covered are 4.

Output from the above example is
Statement Coverage = 1
Branch Coverage = 2
Path Coverage = 4

Also remember the following

  • 100% LCSAJ coverage will imply 100% Branch/Decision coverage
  • 100% Path coverage will imply 100% Statement coverage
  • 100% Branch/Decision coverage will imply
  • 100% Statement coverage
  • 100% Path coverage will imply 100% Branch/Decision coverage

Note: 

  • Both decision coverage and branch coverage are same
  • Decision coverage gives more coverage compared to Statement Coverage.
  • 100% Decision coverage guarantees 100% Statement coverage but not vice versa.
  • LCSAJ means Linear Code Sequence and Jump

White Box Testing Tools

The list of best white box testing tools are as follows

  • Parasoft Jtest
  • Veracode
  • EclEmma
  • JUnit
  • NUnit
  • PyUnit
  • HTMLUnit
  • CppUnit
  • RCUNIT
  • Cucumber

Advantages of White Box Testing

  • Testing can be done early in the SDLC.
  • There is no need to wait for GUI to perform White Box Testing.
  • Testers can detect bugs even in the hidden code.
  • It helps to remove extra lines of code in the program.
  • It is easy to automate
  • Testing is more thorough as it covers all possible code paths

Disadvantages of White Box Testing

  • It is complex and expensive.
  • Testers need to have in-depth knowledge of programming language to perform this testing.
  • Time-consuming when it comes to large scale applications.
  • Maintenance of test scripts becomes a burden when there is frequent redesigning of code.

In Conclusion

White Box Testing is a software testing technique that is based on the application’s internal code structure. We can reduce the effort, risk, cost, and time in the later phases of software testing life cycle by implementing this testing type. Eventhough white box testing can be applied to unit testing, integration testing and system testing. It is always advisable to stick white box testing with just unit and integration levels.

Frequently Asked Questions

What is white box testing in software testing?

In Software Testing, White Box Testing plays a crucial role and it is used to test the internal code of the application.

Why is white box testing needed?

It is used to do test path coverage, code optimization, test automation etc.,

Whata is black box and white box testing?

Both black box and white box testing are the part of box testing.

What are the different types of white box testing?

Types of white box testing are unit testing, integration testing, operations testing, mutation testing, execution testing.

Who will do white box testing?

Usually white box testing is performed by developers and the testers who have programming skills (White box testers)

Related posts:

Get our latest blog posts delivered to your inbox

Subscribe and get popular blog posts about software testing industry.

Rajkumar

Leave a Comment

Share via
Copy link
Powered by Social Snap