# White-Box Testing

> Testing a program while you read its code. Each path gets a test.

**Field:** Software Development  
**Category:** Testing & Quality  
**Also known as:** White Box Testing, Clear-Box Testing, Glass-Box Testing, Structural Testing

## Think of it like

Think of it like a car with the hood up. The mechanic can see each part and test it.

## Definition

White-box testing checks a program while looking at its code. The tester reads the code and writes tests for each path through it. If there is an if, they test the yes branch and the no branch. Unit tests are usually written this way. Test coverage tools show which lines the tests reached.

## Example

Jack sees a discount rule with three branches. He writes three tests, one for each, and coverage shows all three run.

## Why it matters

It finds bugs on paths that users rarely reach but still matter.

## Common mistake

Testing how the code works instead of what it does. Then any tidy-up breaks the tests.

## Three principles

- **Code open.** The tester reads the code.
- **Every path.** One test for each branch.
- **Coverage helps.** See which lines ran.

## Related terms

- [Black-Box Testing](https://learn.benibix.com/term/development/black-box-testing)
- [Unit Test](https://learn.benibix.com/term/development/unit-test)
- [Test Coverage](https://learn.benibix.com/term/development/test-coverage)
- [Static Analysis](https://learn.benibix.com/term/development/static-analysis)

## Told apart from

- [Black-Box Testing vs White-Box Testing](https://learn.benibix.com/compare/black-box-testing-vs-white-box-testing): Black-box testing checks what a program does from the outside, with no look at its code. White-box testing reads the code and tests each path through it. Most teams use both, for different jobs.

![Two panels. Black-box testing: an input goes into a dark closed box and an output comes out, and the tester checks only the output against what the spec says. White-box testing, lit up: the same box is open, showing its inside paths, an if with a yes branch and a no branch, and the tester writes one test for each path.](https://learn.benibix.com/diagrams/dev3-box-testing.svg)

---

Source: https://learn.benibix.com/term/development/white-box-testing
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
