Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site.

We also use third-party cookies that help us analyse how you use this website, store your preferences, and provide the content and advertisements that are relevant to you. These cookies will only be stored in your browser with your prior consent.

You can choose to enable or disable some or all of these cookies but disabling some of them may affect your browsing experience.

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

Statistics cookies collect data to help us understand how visitors interact with the website, enabling us to improve user experience.

Marketing cookies are used to deliver personalized advertisements and track the effectiveness of marketing campaigns.

Unclassified cookies are cookies that we are in the process of classifying, along with the providers of individual cookies.

Friday, 23 May 2025

White Box Testing Examples: 7 Real-World Scenarios & Techniques

Dibya Manas Rout's Profile Image
Dibya Manas Rout
1 year ago...
Blog Image

Table of Contents

    Testing software is not always about checking whether a button works or whether a form submits correctly. Sometimes, you need to look inside the code and understand exactly how the application behaves when different conditions, branches, and execution paths are triggered.

    That is where white box testing comes in.

    White box testing allows developers and testers to examine the internal logic of an application and create test cases around how the code actually works.

    In this guide, we'll explore white box testing examples using familiar scenarios such as login authentication, payment processing, discount calculation, registration forms, shopping carts, banking transactions, and API authentication.

    We'll also look at the techniques behind these examples so you can understand not only what to test, but why each testing matters.

     

    What Is White Box Testing?

    White box testing is a software testing technique where the tester has knowledge of the application's internal code, logic, structure, and execution paths. Instead of testing only what the user sees, white box testing examines what happens inside the application.

    A tester may analyse:

    1. Source code

    2. Conditions

    3. Branches

    4. Loops

    5. Variables

    6. Execution paths

    7. Data flow

    Because the internal structure is visible, white box testing is also known as structural testing, clear box testing, or glass box testing.

    Developers commonly use it during unit and integration testing to verify that individual pieces of logic behave correctly under different conditions.

    Let's understand it with a simple example.

     

    Simple White Box Testing Example

    Imagine a login function with three possible outcomes:

    IF username is empty
        return "Username Required"
    
    IF password is incorrect
        return "Invalid Password"
    
    return "Login Successful"
    

    If we only tested the application using valid credentials, one execution path would work correctly, but we wouldn't know whether the other conditions had been tested.

    A white box tester can see the internal logic and therefore creates test cases for each path.

    Test Case Input Path Tested Expected Result
    TC01 Empty username First condition Username Required
    TC02 Valid username + wrong password Second condition Invalid Password
    TC03 Valid username + correct password Success path Login Successful

     

    Why is this white box testing?

    Because the test cases were designed by looking at the application's internal conditions and execution paths. The tester knows there are multiple branches in the code and deliberately creates tests to execute each one. This is the basic idea behind white box testing.

    Now let's look at more realistic examples.

     

    7 Real-World White Box Testing Examples

     

    White box testing can be applied to almost any software where developers or testers have access to the underlying code.

    Here are seven practical scenarios.

     

    1. Login Authentication – Branch Coverage

     

    Authentication is one of the easiest ways to understand white box testing.

     

    Consider this simplified logic:

    IF account is locked
        return "Account Locked"
    
    IF password is incorrect
        return "Invalid Credentials"
    
    return "Login Successful"
    

    There are several possible branches.

    A tester who understands the code can create tests specifically to execute each one.

    Test Account Password Expected Result
    TC01 Locked Correct Account Locked
    TC02 Active Incorrect Invalid Credentials
    TC03 Active Correct Login Successful

     

    What are we testing?

    We're checking whether every important decision in the authentication logic behaves correctly.

    For example, imagine the developer accidentally wrote the account-lock condition incorrectly.

    Normal UI testing might miss the problem depending on the credentials being used. Branch-focused white box testing deliberately executes that condition.

     

    Technique used → Branch coverage

    The goal is to ensure that the different outcomes of each decision are executed during testing.

     

    2. Payment Processing – Boundary Testing

     

    Payment systems contain many rules around transaction amounts, account limits, payment methods, and validation.

    Imagine an application allows transactions between $1 and $5,000.

     

    The internal logic might look like this:

    IF amount < 1
        reject transaction
    
    IF amount > 5000
        reject transaction
    
    process payment
    

    Instead of testing random payment values, we can focus on the boundaries.

    Test Amount Expected Result
    TC01 $0 Rejected
    TC02 $1 Accepted
    TC03 $4,999 Accepted
    TC04 $5,000 Accepted
    TC05 $5,001 Rejected

     

    Why does this matter?

    Errors frequently occur around minimum and maximum values.

    For example, using:

    amount >= 5000
    

    instead of:

    amount > 5000
    

    would incorrectly reject a valid $5,000 transaction.

    By examining the internal condition, the tester knows exactly which boundary values need attention.

     

    Technique used → Boundary-focused structural testing

    The tests are created around limits explicitly defined within the program logic.

     

    3. Discount Calculator – Path Coverage

     

    Consider an eCommerce application that calculates discounts according to customer type and order value.

    The rules are:

    • Premium customer spending over $500 → 20% discount

    • Regular customer spending over $500 → 10% discount

    • Orders of $500 or less → No discount

    Simplified logic:

    IF order > 500
        IF customer = premium
            discount = 20%
        ELSE
            discount = 10%
    ELSE
        discount = 0
    

    There are several execution paths.

     

    Test Customer Order Expected Discount
    TC01 Premium $700 20%
    TC02 Regular $700 10%
    TC03 Premium $300 0%
    TC04 Regular $300 0%

     

    What does white box testing reveal?

     

    The tester can inspect the nested conditions and identify the different paths through the discount logic.

    This helps uncover issues such as:

    1. Incorrect discount percentages

    2. Wrong customer conditions

    3. Unreachable code

    4. Missing execution paths

    5. Incorrect order-value comparisons

     

    Technique used → Path coverage

    The goal is to execute the meaningful paths through the program's logic.

     

    4. Registration Form – Condition Coverage

     

    Imagine a registration system checks three things:

    IF email is invalid
        show "Invalid Email"
    
    IF password is weak
        show "Weak Password"
    
    IF email already exists
        show "Account Already Exists"
    
    create account
    

    The tester knows each condition exists because the application's internal logic is available.

     

    Test cases could include:

    Test Scenario Expected Result
    TC01 Invalid email Invalid Email
    TC02 Valid email + weak password Weak Password
    TC03 Existing email Account Already Exists
    TC04 Valid new email + strong password Account Created

    Additional tests can combine conditions to check how the system behaves when more than one input is invalid.

     

    What are we testing?

    Each Boolean condition should be evaluated under the appropriate true and false states.

    For example:

    emailIsValid = TRUE / FALSE

    passwordIsStrong = TRUE / FALSE

    emailExists = TRUE / FALSE

    This helps reveal logic that may behave correctly for common inputs but fail under specific combinations.

     

    Technique used → Condition coverage

     

    5. Shopping Cart – Statement Coverage

     

    Consider an eCommerce shopping cart.

    When a customer adds an item, the application might:

    add product
    update quantity
    calculate subtotal
    apply discount
    calculate tax
    calculate final total
    

    Statement coverage checks whether executable statements in the relevant code have actually run during testing.

     

    For example:

    Test Scenario Statements Exercised
    TC01 Add normal product Add + quantity + subtotal
    TC02 Add discounted product Discount calculation
    TC03 Checkout taxable order Tax calculation
    TC04 Complete checkout Final total

     

    Why is statement coverage useful?

    Untested statements can hide defects.

    Suppose the discount calculation executes only when a promotional product is added. If all tests use standard products, that part of the code may never execute.

    Statement coverage helps identify these gaps.

     

    Technique used → Statement coverage

    However, 100% statement coverage does not necessarily mean every logical outcome has been tested. That's why it is often combined with branch and condition coverage.

     

    6. Banking Withdrawal – Decision Coverage

     

    Banking software often contains several conditions before a withdrawal can be approved.

    For example:

    IF account is locked
        decline
    
    IF amount > balance
        decline
    
    IF amount > daily limit
        decline
    
    approve withdrawal
    

     

    This creates several possible outcomes.

    Test Scenario Expected Result
    TC01 Account locked Declined
    TC02 Withdrawal exceeds balance Declined
    TC03 Withdrawal exceeds daily limit Declined
    TC04 All conditions valid Approved

     

    Why is white box testing valuable here?

    A tester can identify every decision in the transaction logic and deliberately execute it.

    For example, imagine the daily withdrawal limit is $1,000.

    Testing $500 alone isn't enough.

    You may also need to test:

    1. $999

    2. $1,000

    3. $1,001

    That combination helps verify both the decision and its boundary.

     

    Technique used → Decision/branch coverage

     

    7. API Authentication – Path Testing

     

    Modern applications often communicate through APIs, making authentication logic another useful white box testing scenario.

    Imagine an API checks:

    IF token is missing
        return 401
    
    IF token is expired
        return 401
    
    IF user lacks permission
        return 403
    
    return requested data
    

     

    The tester can identify the different paths through the authentication logic.

    Test Token Permission Expected Result
    TC01 Missing 401 Unauthorized
    TC02 Expired 401 Unauthorized
    TC03 Valid Insufficient 403 Forbidden
    TC04 Valid Allowed 200 Success

    You could also test malformed tokens, revoked credentials, different roles, and unexpected authentication states depending on the actual implementation.

     

    What can this uncover?

    White box testing may expose:

    1. Missing authorization checks

    2. Incorrect status codes

    3. Unhandled authentication states

    4. Faulty role conditions

    5. Paths that bypass expected validation

     

    Technique used → Path and branch testing

    This is a good example of how white box testing applies beyond traditional desktop or web interfaces to modern APIs and backend services.

     

    White Box Testing Techniques Used in These Examples

     

    The examples above use several white box testing techniques.

    Understanding the differences helps you choose the appropriate test for a particular piece of code.

     

    1. Statement Coverage

     

    Statement coverage measures whether executable statements within the code have been executed by the test suite. For example, if a function contains 20 executable statements and the tests execute 18, statement coverage would be 90%. It is useful for finding code that has never been tested. However, executing every statement does not guarantee that every decision or path has been tested.

     

    2. Branch Coverage

     

    Branch coverage checks whether the possible outcomes of decision points have been executed.

    Consider:

    IF age >= 18
        allow registration
    ELSE
        reject registration
    

    A complete branch test needs at least:

    1. One user aged 18 or above

    2. One user below 18

    Testing only a 25-year-old would execute the condition but wouldn't test the rejection branch.

     

    3. Condition Coverage

     

    Condition coverage examines the individual Boolean conditions within a decision.

    Consider:

    IF userIsActive AND emailIsVerified
        allow access
    

    Tests should exercise different values for:

    1. userIsActive

    2. emailIsVerified

    This becomes particularly useful when a decision contains multiple conditions.

     

    4. Path Coverage

     

    Path coverage goes further by testing different execution routes through the application. A function containing several nested decisions can create multiple paths from beginning to end.

    Testing those paths helps detect errors that only appear under particular combinations of conditions. Complete path coverage can become impractical in complex applications because the number of possible paths grows rapidly, so teams normally prioritise important and high-risk paths.

     

    5. Loop Testing

     

    Loop testing focuses on iterations within the code.

    For a loop processing items in a shopping cart, useful scenarios might include:

    1. Zero items

    2. One item

    3. Several items

    4. Maximum allowed items

    5. Unexpected or invalid values

    This can expose off-by-one errors, incorrect termination conditions, and performance problems.

     

    6. Data Flow Testing

     

    Data flow testing looks at how variables are created, assigned, modified, used, and removed throughout the program.

    For example, a payment application might:

    receive amount
    apply discount
    calculate tax
    calculate final amount
    send final amount to payment gateway
    

    Testing the data flow helps verify that the value remains correct as it passes through each stage.

     

    White Box Testing Example Test Cases at a Glance

     

    Here's how the examples we've covered map to different techniques:

    Real-World Scenario White Box Technique Main Focus
    Login Authentication Branch Coverage Login decision paths
    Payment Processing Boundary/Structural Testing Transaction limits
    Discount Calculator Path Coverage Discount execution paths
    Registration Form Condition Coverage Validation conditions
    Shopping Cart Statement Coverage Executable statements
    Banking Withdrawal Branch Coverage Transaction decisions
    API Authentication Path/Branch Testing Authentication logic

    There isn't always one technique for one scenario.

    In real software projects, developers and QA engineers often combine multiple coverage techniques depending on the complexity and risk of the feature.

     

    White Box Testing vs Black Box Testing

     

    White box and black box testing approach software from different perspectives.

     

    White Box Testing Black Box Testing
    Internal code is visible Internal code is not required
    Tests logic and structure Tests functionality and behaviour
    Focuses on paths, branches and conditions Focuses on inputs and outputs
    Requires knowledge of implementation Can be performed from requirements
    Common in unit-level testing Common in functional/system testing
    Example: Testing every login branch Example: Checking whether login works

     

    Consider the same login feature.

    A black box tester may enter valid and invalid credentials and check the results.

    A white box tester can examine the authentication function, identify every condition and branch, and build test cases specifically to execute them.

    Neither approach replaces the other. Strong software testing strategies often use both.

     

    Advantages of White Box Testing

     

    1. Reveals hidden logical errors

    Because testers can inspect the internal implementation, they can identify conditions and paths that might otherwise remain unnoticed.

     

    2. Improves code coverage

    Coverage metrics can reveal which areas of the code have and haven't been exercised.

     

    3. Detects unnecessary or unreachable code

    Structural analysis can uncover logic that is redundant or impossible to execute.

     

    4. Helps test complex decision logic

    Applications involving calculations, permissions, transactions, and validations often contain numerous branches that benefit from white box testing.

     

    5. Supports earlier defect detection

    Developers can apply white box techniques at the unit level before defects move further through the development lifecycle.

     

    Limitations of White Box Testing

     

    White box testing is powerful, but it cannot solve every testing problem.

     

    Requires technical knowledge

    The tester needs sufficient understanding of programming logic and, in many situations, the actual codebase.

     

    Complex systems create many paths

    Large applications can contain thousands or even millions of possible execution paths. Testing all of them may be unrealistic.

     

    Tests can require maintenance

    When implementation logic changes, code-dependent tests may also need to change.

     

    It doesn't replace user-focused testing

    A function can have excellent code coverage and still provide a poor user experience or fail to meet a business requirement.

    That's why white box testing should normally complement rather than replace black box, integration, system, usability, and other testing approaches.

     

    White Box Testing Tools

    The tools used for white box testing depend heavily on the programming language, application architecture, and type of testing being performed.

    Common examples include:

    1. JUnit – Unit testing for Java applications

    2. pytest – Testing framework commonly used with Python

    3. Jest – JavaScript and TypeScript testing

    4. NUnit – Testing for .NET applications

    5. xUnit.net – Unit testing for .NET

    6. JaCoCo – Java code coverage analysis

    7. Istanbul/nyc – JavaScript code coverage

    8. coverage.py – Python code coverage

    These tools can help teams automate tests and understand how much of the underlying code is being exercised.

    A high coverage percentage, however, should not be treated as proof that an application is defect-free. Test quality matters more than chasing a coverage number.

     

    Conclusion

    White box testing becomes much easier to understand when you stop thinking about it as a definition and start looking at the application's internal decisions.

    1. A login function has branches.
    2. A payment system has boundaries.
    3. A discount calculator has multiple paths.
    4. A registration form contains conditions.
    5. A shopping cart executes multiple statements.
    6. A banking system makes approval decisions.
    7. An API follows authentication and authorization paths.

    White box testing allows developers and testers to turn those internal structures into deliberate test cases.

    The objective isn't simply to execute more code. It is to understand which parts of the code are being tested, which paths remain untested, and where defects are most likely to hide.

    At Rasonix, we approach software quality as part of the development process rather than something added at the end. Combining structured testing with reliable engineering practices helps teams identify issues earlier and build software that behaves predictably in real-world conditions. Contact us now. 

     

    Frequently Asked Questions

    What is a simple example of white box testing?

    A simple example is testing a login function after examining its internal code. If the function contains separate conditions for an empty username, incorrect password, locked account, and successful login, the tester creates test cases that execute each condition.

     

    What are real-life examples of white box testing?

    Common real-world examples include testing login authentication branches, payment limits, discount calculations, registration validation, shopping-cart calculations, banking transaction rules, and API authentication paths.

     

    What are the main white box testing techniques?

    Common techniques include statement coverage, branch coverage, condition coverage, path coverage, loop testing, and data flow testing. Each technique examines a different aspect of the application's internal structure.

     

    Who performs white box testing?

    White box testing is commonly performed by developers, software development engineers in test (SDETs), automation engineers, and technically skilled QA engineers who understand the application's implementation.

     

    Is unit testing the same as white box testing?

    No. Unit testing describes the level of testing, while white box testing describes an approach to designing tests based on internal code structure. Many unit tests use white box techniques, but the terms are not interchangeable.

     

    What is the difference between white box and black box testing?

    White box testing uses knowledge of the application's internal code and logic to design tests. Black box testing focuses on the application's external behaviour, inputs, and outputs without requiring knowledge of how the underlying code works.

     

    What is branch coverage in white box testing?

    Branch coverage measures whether different outcomes of decision points have been executed during testing. For an if/else condition, for example, tests should execute both the if and else branches where they are feasible.

    Contact Menu

    Request a Callback

    Subscribe Modal Image

    Stay Updated with Rasonix!

    Subscribe for updates, job alerts, and more—all in one place!