White Box Testing: A Complete Guide with Techniques, Examples, & Tools

By Vijay

By Vijay

I'm Vijay, and I've been working on this blog for the past 20+ years! I’ve been in the IT industry for more than 20 years now. I completed my graduation in B.E. Computer Science from a reputed Pune university and then started my career in…

Learn about our editorial policies.
Updated February 10, 2025

This article provides a comprehensive overview of White Box Testing, including techniques, examples, and tools.

If we go by the definition, “White box testing” (also known as clear, glass box, or structural testing) is a testing technique that evaluates the code and the internal structure of a program.

White box testing involves looking at the structure of the code. When you know the internal structure of a product, you can conduct tests to ensure that the internal operations are performed according to the specifications. All internal components should have undergone adequate testing. 

How to Perform White Box Testing

overview of White Box Testing

My Experience

It’s almost a decade now since I’ve been in the Software testing field and so far I have noticed that the testers are the most enthusiastic in the whole software industry.

The prime reason behind this is that testers always have some scope to learn. Be it a domain, process, or technology, a tester can have complete development if they wish to.

However, the saying “There is always a darker side” is also true.

Testers also indeed avoid the type of testing that they feel to be very complicated and the developer’s piece of cake. Yes, it is referred to as “White Box Testing”.

White Box Testing Coverage

White Box Testing ensures coverage of the code’s specifications.

#1) Code coverage

#2) Segment coverage: Ensure that each code statement is executed once.

#3) Branch Coverage or Node Testing: Coverage of each code branch.

#4) Compound Condition Coverage: For multiple conditions, test each condition with multiple paths and a combination of different paths to reach that condition.

#5) Basis Path Testing: Each independent path in the code is taken for testing.

#6) Data Flow Testing (DFT): In this approach, you track the specific variables through each calculation, thus defining the set of intermediate paths through the code.

DFT reflects dependencies, but it is mainly through sequences of data manipulation. In short, each data variable is tracked and its use is verified. This approach uncovers bugs like variables used but not initialized, declared but not used, and so on.

#7) Path Testing: Path testing is where all paths through the code are defined and covered. It’s a time-consuming task.

#8) Loop Testing: These strategies relate to testing single loops, concatenated loops, and nested loops. Independent and dependent code loops and values are tested with this approach.

Why do We Perform WBT

To ensure the following:

  • All independent paths within a module have been exercised at least once.
  • Their true and false values verify all logical decisions.
  • All loops are executed at their boundaries and within their operational bounds of internal data structure validity.

To discover the following bugs:

  • Logical errors creep into our work when we design and implement functions, conditions, or controls that are external to the program.
  • Design errors are because of the difference between the logical flow of the program and the actual implementation.
  • Typographical errors and syntax checking.

Does this testing require detailed programming skills?

We need to write test cases that ensure the complete coverage of the program logic.

For this, we need to know the program well, i.e. We need to know the specifications and the code to be tested. Knowledge of programming languages and logic is required for this type of testing.

Limitations

Difficult to test every path of the loops in the program. This means exhaustive testing is not possible for large systems. This does not mean that WBT is not effective. Selecting important logical paths and data structures for testing is practically possible and effective.

The Difference Between White-Box and Black-Box Testing

To put it in simple terms:

Under Black box testing, we test the software from a user’s point of view, but in the white box, we see and test the actual code. In black box testing, we perform testing without seeing the internal system code, but in WBT, we see and test the internal code.

Both the developers and testers use the white box testing technique. It helps them to understand which lines of code have been executed and which are not. This may indicate that there is either a missing logic or a typo, which eventually can lead to some negative consequences.

Recommended read => A Complete Guide to Black Box Testing

Steps to Perform WBT

Step #1: Understand the functionality of an application through its source code. This means that a tester must be well-versed in the programming language and the other tools as well as techniques used to develop the software.

Step #2: Create the tests and execute them.

When we discuss the concept of testing, “coverage” is considered to be the most important factor. Here I will explain how to have maximum coverage from the context of White box testing.

Also read => Cause and Effect Graph – Dynamic Test Case Writing Techniques For Maximum Coverage

Types and Techniques of White Box Testing

There are several types and different methods for each white box testing type.

See the image given below for your reference.

White box testing types

Today, we are going to focus mainly on the execution testing types of the unit testing white box technique’.

3 Main White Box Testing Techniques include:

  1. Statement Coverage
  2. Branch Coverage
  3. Path Coverage

Note that the statement, branch, or path coverage does not identify any bugs or defects that need to be fixed. It only identifies those lines of code which are either never executed or remain untouched. Based on this, we can focus on further testing.

Let’s understand these techniques one by one with a simple example.

#1) Statement Coverage

In a programming language, a statement is nothing but a line of code or instruction for the computer to understand and act accordingly. A statement becomes an executable statement when it gets compiled and converted into the object code and performs the action when the program is in running mode.

Hence “Statement Coverage”, as the name itself suggests, is the method of validating whether every line of the code is executed at least once.

#2) Branch Coverage

“Branch” in a programming language is like the “IF statements”. An IF statement has two branches: True and False. So in Branch coverage (also called Decision coverage), we validate whether each branch is executed at least once.

In the case of an “IF statement”, there will be two test conditions:

  • One to validate the true branch.
  • Else to validate the false branch.

Hence, in theory, Branch Coverage is a testing method that when executed ensures that every branch from each decision point is executed.

#3) Path Coverage

Path coverage tests all the paths of the program. This is a comprehensive technique that ensures that all the paths of the program are traversed at least once. Path Coverage is even more powerful than Branch coverage. This technique is useful for testing complex programs.

Let’s take a simple example to understand all these white-box testing techniques.

Suggested Read => Different Types of Testing

White Box Testing Example

Consider the simple pseudocode given below:

INPUT A & B
C = A + B
IF C>100
PRINT “ITS DONE”

For Statement Coverage, we would only need one test case to check all the lines of the code.

This means:

If I consider TestCase_01 to be (A=40 and B=70), then all the lines of code will be executed.

Now the question arises:

  1. Is that sufficient?
  2. What if I consider my Test case as A=33 and B=45?

Because the Statement coverage will only cover the true side, for the pseudo-code, only one test case would NOT test it. As a tester, we have to consider the negative cases as well.

Hence, for maximum coverage, we need to consider Branch Coverage”, which will evaluate the “FALSE” conditions.

In the real world, you may add appropriate statements when the condition fails.

So now the pseudocode becomes:

INPUT A & B

C = A + B
IF C>100
PRINT “ITS DONE”
ELSE

PRINT “ITS PENDING”

Since Statement coverage is not sufficient to test the entire pseudo code, we would require Branch coverage to ensure maximum coverage. So for Branch coverage, we would require two test cases to complete the testing of this pseudo code.

TestCase_01: A=33, B=45

TestCase_02: A=25, B=30

With this, we can see that every line of the code is executed at least once.

Here are the Conclusions that have been derived so far:

  • Branch Coverage ensures more coverage than Statement coverage.
  • Branch coverage is more powerful than Statement coverage.
  • 100% Branch coverage itself means 100% statement coverage.
  • However, 100 % statement coverage does not guarantee 100% branch coverage.

Now let’s move on to Path Coverage:

As mentioned earlier, Path coverage is used to test complex code snippets, which involve loop statements or a combination of loops and decision statements.

Consider this pseudocode:

INPUT A & B
C = A + B
IF C>100
PRINT “ITS DONE”

END IF
IF A>50
PRINT “ITS PENDING”
END IF

Now, to ensure maximum coverage, we would require 4 test cases.

How? Simply there are 2 decision statements, so for each decision statement, we would need two branches to test. One for true conditions and the other for false conditions. So for 2 decision statements, we would require 2 test cases to test the true side and 2 test cases to test the false side, which makes 4 test cases.

To simplify this, let’s consider the flowchart of the pseudocode we have:

Path coverage 1

Further Reading => How To Make A Flowchart In MS Word

In order to have full coverage, we would need the following test cases:

TestCase_01: A=50, B=60

TestCase_02: A=55, B=40

TestCase_03: A=40, B=65

TestCase_04: A=30, B=30

So the paths covered will be:

Path coverage 2

Red Line – TestCase_01 = (A=50, B=60)

Blue Line = TestCase_02 = (A=55, B=40)

Orange Line = TestCase_03 = (A=40, B=65)

Green Line = TestCase_04 = (A=30, B=30)

=>> Contact us to suggest a listing here.

White Box Testing Tools

Given below is a list of the top white box test tools.

#1) Veracode

Veracode

Veracode’s white box testing tools will help you identify and resolve software flaws quickly and easily at a reduced cost. It supports several application languages like .NET, C++, JAVA, etc, and also enables you to test the security of desktop, web, and mobile applications. Still, there are several other benefits of the Veracode tool.

Website: Veracode

#2) EclEmma

EclEmma

EclEmma was initially designed for test runs and analysis within the Eclipse workbench. It is considered a free Java code coverage tool and has several features as well. If you want to install or get more details about EclEmma, please refer to the link provided.

=> Download EclEmma

#3) RCUNIT 

RCUnit

RCUNIT is a framework used for testing C programs. RCUNIT can be used accordingly based on the terms of the MIT License. It is free to use and to install or know more about it.

=> Download RCUNIT

#4) cfix

cfix is one of the unit testing frameworks for C/C++ which solely aims at making test suites development as simple and easy as possible. Meanwhile, cfix is typically specialized for NT Kernel mode and Win32.

=> Download cfix

#5) Googletest 

Googletest

Googletest is Google’s C++ test framework. Test Discovery, Death tests, Value-parameterized tests, fatal & non-fatal failures, XML test report generation, etc are a few features of Googletest but there are several other features as well. Linux, Windows, Symbian, and Mac OS X are a few platforms where Googletest has been used.

=> Download Googletest

#6) EMMA

Emma

Emma is an easy-to-use free JAVA code coverage tool. It includes several features and benefits. To Download and know more about Emma, please check the link given below.

=> Download EMMA

#7) NUnit

NUnit

NUnit is an easy-to-use open-source unit testing framework that does not require any manual intervention to judge the test results. It supports all .NET languages. It also supports data-driven tests and tests run parallel under NUnit.

Earlier releases of NUnit used the NUnit license but NUnit 3 is released under an MIT license. But both licenses allow free use without any restrictions. To download and know more about NUnit please check the link given below.

=> Download NUnit

#8) CppUnit

CppUnit

CppUnit is a unit testing framework written in C++ and is considered the port of JUnit. The test output for CppUnit may be either in the XML or text format. It creates unit tests with its class and runs tests in the test suites. It is licensed under LGPL. To download and know more about CppUnit please check the link given below.

=> Download CppUnit

#9) JUnit

JUnit

JUnit is a simple unit testing framework that supports test automation in the Java Programming Language. It mainly supports Test Driven Development and provides a Test coverage report as well. It is licensed under an Eclipse Public License. For more information on JUnit and to download it at no cost, please visit the link provided.

=> Download JUnit

#10) JSUnit

JsUnit

JSUnit is considered to be the port of JUnit to JavaScript. It is an open-source unit testing framework to support Client-sided Javascript. It is licensed under GNU Public License 2.0, GNU Lesser Public License 2.1, and Mozilla Public License 1.1. To download and know more about JSUnit please check the link given below.

=> Download JSUnit

Also, check all the tools that we have listed under Static code analysis here.

Don’t hesitate to suggest additional simple or advanced tools you use for the white box technique.

Conclusion

Relying only on black box testing is not sufficient for maximum test coverage. We need to have a combination of both black and white box testing techniques to cover maximum defects.

If done properly, white box testing will certainly contribute to the software quality. It’s also good for testers to participate in this testing as it can provide the most “unbiased” opinion about the code.

Feel free to ask any questions or express any doubts about the methods we discussed in this article in the comments section below. We value your feedback and would love to hear from you.

=>> Contact us to suggest a listing here.

Was this helpful?

Thanks for your feedback!

Recommended Reading

  • black box vs white box testing

    A Thorough Study of Black Box Testing Vs White Box Testing: Software testing includes several types of testing and as a software tester, we must know how each of them is performed. Among the various types of testing, one of the most confusing topics is that of the Black box…

  • Grey Box Testing Tutorial With Examples

    This tutorial is a complete guide to Grey Box Testing, its advantages, examples, and tools, etc.: Grey box testing also spelled as Gray box testing is known as Translucent testing. It is effectively used for Web-based applications. This software testing technique is beneficial in Integration testing, Penetration testing, and Domain…

  • Black Box Testing

    I have covered what is White box Testing in previous article. Here I will concentrate on Black box testing. BBT advantages, disadvantages and and How Black box testing is performed i.e the black box testing techniques. Black box testing treats the system as a "black-box", so it doesn't explicitly use…

  • Functional Testing Vs Non-Functional Testing

    Know the Difference Between Functional Testing Vs Non-Functional Testing with Examples: Software Testing is broadly categorized into Functional and Non- Functional Testing. Let us discuss in detail about these testing types along with the exact differences between both functional and non-functional tests. What is Functional Testing? Functional testing is testing the…

  • DataWaewhouse ETL Testing

    This Tutorial Covers Goals & Significance of Data Warehouse Testing, ETL Testing Responsibilities, Errors in DW and ETL Deployment in detail: In this In-Depth Data Warehouse Training Series, we had a look at the What Is ETL Process in Data Warehouse in detail in our previous tutorial. This tutorial will give…

  • Alpha Versus Beta Testing

    Alpha and Beta testing are Customer Validation methodologies (Acceptance Testing types) that help in building confidence to launch the product and thereby result in the success of the product in the market. Even though they both rely on real users and different team feedback, they are driven by distinct processes,…

  • Portability testing

    Introduction to Portability Testing: Portability testing is a non-functional testing methodology that determines the ease or difficulty with which a software component or an application can be moved from one environment to another. The test results obtained from Portability Testing helps in finding out how easily a software component from…

  • Client-server and web based testing (1)

    An extensive analysis of Client Server Testing, Web Testing & Desktop Testing with Pros and Cons. Get to know how to test these types of applications with simple examples: This tutorial will give you the answers to the above questions in detail along with simple examples for your easy understanding.…


52 thoughts on “White Box Testing: A Complete Guide with Techniques, Examples, & Tools”

  1. Very Good Explanation. Many thanks for posting it. I am currently preparing for CTFL . Please suggest me any good reads as my exam is due in 2 and half weeks time. I am an ICT teacher want to switch in software testing.

    Reply
  2. Can any one please explain the completely the difference between condition coverage & path coverage or they are same?

    Reply
  3. Surinder from Canada preparing for CTFL entrance exam of Software testing. The testing techniques were explained in very simple way. I wish you guys open institute in Ottawa Canada. Thank you guys for sharing

    Reply
  4. can i have about white box testing and its types with any simple C language code as an example and how the code is analysed in each test

    Reply
  5. Very nice.
    In the Branch Coverage, the example is incorrect. Psl correct.

    TestCase_01: A=33, B=45

    TestCase_02: A=25, B=30

    In this case, it allways goes to else part, never executed first part.

    Reply
  6. It’s an interesting article, but GenRocket has an automated platform and process that does white box testing, fully tests and cuts the time and cost of testng way down.

    Reply
  7. Hello Sir,
    I am vismay.
    I am working as a QA Engineer in company and have 3 years of experience in manual testing and 6 month experience in automation.
    I want to start freelancing please give me suggestions regarding this, how can i start and prerequisites?

    Reply
    • Hi vismay i am rohit plzz send your details we provide online trainings for our students all over the globe if our client needs such technology we wilp contact you.
      Rohit Shingade
      Training Director
      StarTech online Training

      Reply
  8. hello shilpa mem & Vijay sir:This is a good article about
    how to perform WBT.actually most of the people follow the BBT because they have not proper knowledge about coding,tools or frameworks etc.but in thie time in market WBT is most important technique to find a defect in software application or product.
    I hope this article gives a new direction to think about WBT.
    Thanks for this article…!!

    Reply
  9. A clearer example of when full path should be used would be helpful. Full path can be extremely time consuming, and so long as full decision and statement coverage has been achieved, it might also be unnecessary. Typically full path is reserved for safety or critical systems.

    Reply
  10. Can you please help and draw flowchart for this task.

    1. Pick up and read the newspaper.
    2. Look at what is on television.
    3. If there is a program that you are interested in watching then switch the television on and watch the program.
    4. Otherwise.
    5. Continue reading the newspaper.
    6. If there is a crossword in the newspaper then try and complete the crossword.

    A. SC = 1 and DC = 3.
    B. SC = 1 and DC = 2.
    C. SC = 2 and DC = 3.
    D. SC = 2 and DC = 2.
    E. SC = 1 and DC = 1.

    Reply
  11. In the Branch Coverage, the example is incorrect. Psl correct.

    TestCase_01: A=33, B=45

    TestCase_02: A=25, B=30

    In this case, it allways goes to else part, never executed first part.

    Reply
  12. I read so many stuffs on White Box testing but didn’t understand until I read this article. Thanks! Thorough and easy to understand!

    Reply
  13. Thanks for the nicely organized article.

    I have a confusion about the ‘path coverage’. Test case 1 and Test Case 3 (in fact Test case 2 as well) is a repetitive test for the TRUE side of decision statement 2. Here the total independent path is identified 4. But if we apply the cyclomatic complexity metric here, the total number of independent path would be 3; which reduces the requirement of 1 test case.

    Reply

Leave a Comment