White Box Testing Tutorial for Beginners

White Box Testing is one of the software testing methods in which the structure and the implementation of the software are known to the one who is testing it. The tester selects inputs and determines the outputs for the same. Some other names for white box testing are glass box testing, clear box testing, structural testing. Programming knowledge and how it is implemented is essential to know. This method is named so because the software program is like a white/transparent box and testers can see through it clearly.

white box testing

For Example: 

C = A + B
IF C>100
  • First, assign the value of A and B. suppose A=60 and B=50.
  • Second, now C is assigned the value of A+B, A=60, B=50 hence C=110.
  • Third, will check if C>100 and in this case it’s true hence we will get the result it’s DONE.

Steps to Initiate White Box Testing

  •  Design all the test case scenarios, test cases, and prioritize them according to high priority numbers.
  • Study the code at runtime in order to examine the resource utilization and the time taken by various operations.
  • Test the internal functions that take place. Internal functions such as nonpublic methods, interfaces.
  • Focus on testing of control statements like loops and conditional statements which checks the efficiency for different data inputs.
  • The last step in white box testing is security testing which checks all possible security loopholes.

White Box Testing Techniques

Following are the White Box Testing techniques:

  • Statement Coverage
  • Decision Coverage
  • Branch Coverage
  • Condition Coverage
  • Multiple Condition Coverage
  • Finite State Machine Coverage
  • Path Coverage
  • Control flow testing
  • Data flow testing

Now let’s discuss it in detail.

  • Statement Coverage
    This technique involves the execution of all statements of the code at least once. It calculates the total number of executed statements in the source code out of the total statements present in the source code.
(Statement coverage = No of statements Executed/Total no of statements in the source code * 100)
  • Decision Coverage
    It covers all possible outcomes of each and every Boolean condition of the code by using a control flow graph or chart. The above-mentioned technique reports true and false outcomes of Boolean expressions.
  • Branch Coverage
    It is one of those techniques that is used to cover all branches of the control flow graph. The branch coverage technique and decision coverage technique are very similar, but the difference between the two is that the decision coverage technique covers all branches of each decision point whereas branch testing covers all branches of every decision point of the code.
Branch Coverage
  • Condition Coverage
    In this technique each one of the Boolean expressions have been evaluated to both TRUE and FALSE. Condition coverage is also called Predicate Coverage.
  • Multiple Condition Coverage
    Multiple Condition Coverage, is a technique that only applies to multiple statements.
  • Finite State Machine Coverage
    Finite State Machine coverage is one of the most complex types of code coverage because it works on the behavior of the design. By using this all bugs related to finite state machine design can be found. 
  • Path Coverage
    Path coverage testing deals with the total number of paths that could be covered by a test case. 
  • Control Flow Testing
    Control Flow Testing examines the execution order of statements or instructions of the program through a control structure.
  • Data Flow Testing
    Data Flow testing helps to find the test paths of the  program according to the variables mentioned in the program. 

Levels Applicable to White Box Testing

White box testing is applicable to the following levels:

  • Unit Testing: A level of testing where individual units are tested as a group. The purpose is to find out the faults between integrated units. It is the second level of testing that is performed.
  • Integration Testing: It is a level of testing where integrated software is tested. The purpose is to examine the system’s compliance. It is the third level of testing performed after integration testing and before acceptance testing.
  • System Testing: A software is tested for functionality at this level. The main aim is to evaluate the system’s compliance with the functional requirements.

Types of White Box Testing 

  • Unit Testing
    Unit Testing is the first type of software testing that is usually done on applications. It is performed on each unit or block of code while it is developed. Unit testing is performed by the programmer. It helps to identify various bugs that too in the early stages of the software development cycle. Identifying bugs in this stage is cheaper and easy to fix.
  • White Box Penetration Testing
    In this testing, the software tester has full information on the application source code, IP addresses involved, and all server information. The aim is to expose security threats by attacking the source codes from different angles.
  • Testing for Memory Leaks
    A memory leak is the leading cause of slower running applications. A quality assurance specialist who can detect memory leaks is essential in cases where you have a slow running software application.
  •  White Box Mutation Testing
    Mutation testing is generally used to discover the best possible coding techniques that can be used for expanding a software solution.

Tools for White Box Testing

  • NUnit: NUnit is a testing framework that is available for all the .Net languages. The third version has been completely rewritten with many new features, supporting a wide range of .NET platforms.
  • GTest: GTest or Google Test is a unit testing library for the C++ programming language. It compiles a variety of POSIX and Windows platforms, allowing unit testing of C sources as well as C++.

Pros and Cons of White Box Testing

● Let the tester know when testing is completed.
● Techniques are easy to automate.
● Optimization becomes an easy task for the programmer.
● It is easy to remove the part of the code that is not necessary for the functionality of the program.
● It is much costlier than others
● It is not possible to test each condition in the code.
● It fails to find the missing functionality of the program.

Recommended Articles