White box testing


White box testing is the testing technique which tests the internal structure and implementation of the product by making them visible to the tester. Here internal structure implies design, code, dataflow, and databases. The objective of white box testing is to verify the internal workflow of the product. The thoroughness of the tests is measured through code coverage. To define, code coverage is the percentage of lines of code exercised through the tests out of total lines of code. The other common names for white box testing are Clear box, Glass box, transparent box or Structural testing.

Performing white box testing requires programming, database, and design knowledge of the product. Moreover, testers also require the knowledge of tools like coverage tools, debuggers for white box testing.

White box testing example

The typical example of white box testing is component testing of the product. By definition, Component testing means testing the individual component units of the product which can either be single program or group of programs together forming a module. Thus, these tests focus on the evaluation of that particular module. One can write JUnit or Cucumber tests for this type of components testing. Typically, these tests invoke methods or functions providing them with the input data and then evaluate their output by comparing with expected results.

White box testing characteristics

  • In white box testing, design, code, and data flow form the basis of testing. Therefore, test scenarios and conditions are obtained from the internal architecture of the product.
  • It requires coding and design knowledge from the tester. Moreover, he should also have knowledge of tools to perform the testing and calculate the coverage.
  • Test coverage is the measure of thoroughness of the testing. To define, it is the lines of code covered by tests divide by total lines of code in a particular test item.
  • It exposes internal security loopholes, dead code, dataflow defects, and poor coding standards.

White box testing techniques

The white box testing techniques aim at exercising the internal code and structure of the code. The two of the common techniques are:

Statement coverage

This technique targets to traverse all the statements of code through the tests. Hence, the number of tests should be enough to exercise each statement of the code.

Branch coverage

This technique targets to traverse all the decision making branches of the code.

For example, if we have the following code

int A; 
int B; 
If (A > B) 
   C = A - B; 
} Else If (A < B) 
   C = B - A; 
} Else 
   C = A; 

For statement coverage, we need 3 test cases where

  1. A is greater than B
  2. A is less than B
  3. A is equal to B

Similarly, for branch coverage, we need 3 test cases as above to cover all the branches of the code.


  • It identifies the unreachable code, memory leaks, and other coding related errors.
  • White box testing helps maintain clean and optimum code conforming to the coding standards.
  • These test cases are easy to automate as each targets a section of code.
  • It helps improve the quality of the product enormously.


  • White box testing is an expensive and time-consuming activity
  • Testers require in-depth knowledge of the programming language, tools, and internal working.
  • Changes in the code require changes in the test cases.
  • Identifying the missing functionalities is not possible as the testing of existing code is done.
  • It is a complex process and requires the right set of skills to perform it effectively.

Difference between white and black box testing

White box testingBlack box testing
White box testing tests the internal design, code, and dataflows of the product.Black box testing tests the input-output behavior of the product.
The tester needs knowledge of coding, internal structure, and coverage toolsThe tester needs functional knowledge of the product.
It extracts test cases from the design documents, code, and dataflows.On the other hand, black box testing extracts test cases from requirements documents, use cases, specifications.
It is applicable to unit, integration, and regression testing levels.It is applicable to system test, performance tests and user acceptance testing levels.


White box testing is complementary to black box testing. Both together can improve the quality of the product manifold. But at the same time, it’s difficult for the projects to find budget and time to incorporate each individually. In modern times, the target of projects is to get maximum quality upliftment with minimum time and budget. Therefore, they choose the best fit testings as per the product’s quality requirements.

Translate ยป