White Box Testing in Software Engineering

White Box Testing

  • White box testing is also called Clear Box Testing, Open Box Testing, Glass Box Testing, Transparent Box Testing, Code-Based Testing and Structural Testing.
  • white box testing is a software testing in which the internal structure of the program is tested. The tester knows the interior functionality and design of the code and internal paths. This testing is usually done by developers.
  • White-box is a term which is used because of see-through box concept. The white box means that the tester can see internal working through the box. Hence this method is named white box testing. 
  • In white-box testing, technical and programming skills are used to design the test cases. The tester selects the inputs to exercise paths through the code and determine the expected outputs. White-box testing can be applied at the unit, integration and system levels of the software testing process. Tester find out which unit/statement of the code is malfunctioning.
White Box Testing

This testing is used to find errors in the following types :

  • Control flow testing
  • Data flow testing
  • Branch testing
  • Statement coverage
  • Decision coverage
  • Prime path testing
  • Path testing
  • Loop testing

Techniques of White box testing :

There are some techniques which is used for white box testing –

1.Statement coverage:

Statement coverage is a testing technique in which tester traverse all statements and ensure that each statement of the code is executed at least once. Hence each line of the code is verified. This technique make sure that all the statements executed without any error or issues.In the flowchart, all nodes are covered and traverse at least once and it also helps to focus on the code in which error is present.

2. Branch Coverage :

Branch coverage is a technique used for testing in which test cases are designed so that each branch are tested at least once. This technique analyze every possible ways of the system. In the case of flowchart, every edge must be traversed at least once and ensure that the no branch behaves abnormal in the application.

3. Path Coverage :

Path Coverage is a software testing technique where all possible paths are defined and covered .paths are executable statements from entry to exit points in the system. It’s a time-consuming task.

4. Loop Testing :

By using this strategy, independent and dependent code loops and values are tested. Errors often occur at the beginnings and ends of loops.This strategy related to testing loops –

  • Simple loops
  • Nested loops
  • Concatenated loops

5. Basis Path Testing :

In this basis path testing technique, control flow graphs are made from code and then Cyclomatic complexity is calculated. cyclomatic complexity defines the number of independent paths so that the minimal number of test cases can be designed.
Steps of this technique :

  1. Build control flow graph from the code
  2. Calculate the cyclomatic complexity
  3. Find the independent paths
  4. Develop test cases corresponding to each independent path

Flow graph : Flow graph is a directed graph which consist nodes, represents a sequence of statements and edges.

Cyclomatic Complexity : Cyclomatic complexity is a measure defines the number of independent paths.

For a graph G, V(G) is its cyclomatic complexity.
How to Calculate V(G) :

We can calculate cyclomatic complexity in three ways.

  1. V(G) = P + 1
  • P is the number of predicate nodes

2. V(G) = E – N + 2

  • where E is the number of edges and N is the total number of nodes

3. V(G) = Number of non-overlapping regions in the graph


Cyclomatic Complexity

V(G) = 3 ,By applying any of the above formula on this flow-chart
Independent paths = 3

  • P1: 1- 2- 3- 5- 6
  • P2: 1- 2- 4- 5- 6
  • P3: 1- 2- 3- 5- 1- 2- 4- 5- 6 

Advantages of White box testing :

  • Entire code and structures are tested in the white box testing.
  • It results in the optimization of code removing error and helps in removing extra lines of code.
  • This testing can start at an earlier stage.
  • White box testing is easy to automate.
  • Identify the Dead Code or other issues.
  • This testing covers all the possible test scenario because tester have knowledge about technical and programming knowledge.

Disadvantages of White box testing :

  • This testing is very expensive and time-consuming.
  • Redesign of code needs test cases to be written again.
  • Missing functionalities cannot be detected.
  • This technique can be very complex and at times not realistic.
  • White-box testing requires a programmer with a high level of knowledge due to the complexity of the level of testing that needs to be done.
  • At sometimes, it is not realistic to be able to test every single existing condition of the application.