QA · Read 8 min

Black box vs white box: two ways of looking at the same code

One tests what the software does; the other tests how it does it. They do not compete: they complete each other. Picking just one leaves you with half the risk map.

The difference fits in a single sentence: a black box test looks at the software from the outside, without seeing the code, and checks what it does; a white box test looks from the inside, with the code in full view, and checks how it does it. The first asks whether the result is correct. The second asks whether every path in the program actually ran. They are neither rivals nor stages: they are two angles on the same object, and anyone who uses only one is left with half the risk map.

The name comes from a simple image. A black box is opaque: you feed in an input, an output comes out, and you never see what happens inside. A white box (or glass box) is transparent: you see the wires, the branches, the loops. That metaphor decides what information the tester uses to design the test cases, and that is why each approach catches faults the other lets slip by. This article separates the two, shows the concrete techniques of each and explains why any serious test plan combines them on purpose.

01 · from the outsideBlack box: testing what it does, without seeing the code

In a black box test the tester treats the system as an opaque box. All they know is the specification: what it should receive and what it should return. They design their cases from the requirements, not from the code, which is why they can be written by someone who does not know how to program, or before the code even exists. The ISO/IEC/IEEE 29119-4 standard, devoted to test techniques, groups these as specification based techniques [2].

Its value is that it verifies behavior exactly as the user experiences it, without being biased by how it is built inside. Its limit is the mirror image of the same fact: since it does not see the code, it has no idea which parts were never run. It can pass every case and still leave entire branches of the program untouched.

The black box does not know how the software is built. And that is precisely why it finds what the programmer took for granted.

The classic black box techniques, all described in the ISTQB syllabus [1], are these:

Figure 1 · the two angles on the same system
BLACK BOX looks from outside ? in out input and output only WHITE BOX looks from inside sees every branch of the code
It is the same program observed in two ways. The black box judges by the result; the white box follows the internal path. Each angle reveals faults the other cannot see.

02 · from the insideWhite box: testing how it does it, with the code in view

In a white box test the tester does know the code. They design the cases to walk through its internal structure: every statement, every branch of an "if/then", every condition inside those branches. The goal is not only that the result is correct, but that no part of the program is left unrun during testing. ISTQB calls these structure based techniques [1], and ISO/IEC/IEEE 29119-4 catalogs them as structural test techniques [2].

The measure that comes out of this is coverage: what percentage of the structure your tests touched. There are several levels, and they get more demanding as you go deeper:

100 % coverage is not 100 % quality

Reaching full statement coverage only guarantees that every line ran, not that it did the right thing. A test can execute a line and check nothing about its result. Coverage measures how much code you touched, not how much you verified. It is an indicator of gaps (what is not covered is guaranteed risk), not a certificate of the absence of errors.

The white box does not ask whether the software serves the user. It asks whether your tests really walked through the program.

That is why the white box lives above all in unit testing, where the programmer tests their own code with the structure right in front of them. There a coverage tool tells them, line by line, which branches were never run, and those orphan branches are usually exactly where the fault nobody thought to test is hiding.

Figure 2 · statement coverage vs branch coverage
start balance sufficient? YES branch (tested) NO branch (untested)
A single case that goes through the "yes" branch can run every visible statement and still leave the "no" branch untouched. High statement coverage, half branch coverage: that is where the error that escapes to production lives.

03 · togetherWhy they complement each other and are not a choice

The temptation is to ask which one is better. That is the wrong question, because each approach is blind exactly where the other sees. The black box confirms that the system does what the user expects, but it does not tell you what code went untested. The white box confirms that you walked through the program, but it does not tell you whether what it does makes sense for the business: you can have 100 % coverage of a tax calculation that is wrongly specified from the requirement onward.

An example makes it clear. Imagine a function that approves a loan. With the black box you test combinations of income, debt and age, and you verify that the final decision is the correct one according to the policy. With the white box you open the code and discover a branch that only fires when the debt is exactly zero, a case your equivalence partitions never prioritized. Neither approach, on its own, covers both gaps. Together, they do.

The healthy way to combine them is by levels of the testing pyramid. In unit tests, where the programmer has the code in front of them, the white box guided by coverage dominates. In system and acceptance tests, where visible behavior is what matters, the black box guided by the requirements dominates. There is also a middle ground, the gray box, where the tester knows something about the internal structure (the database schema, an API) without reaching the detail of the code, and uses it to design better black box cases.

ISTQB keeps this classification precisely so that a test plan covers both angles deliberately and not by accident, and ISO/IEC/IEEE 29119-4 standardizes the concrete techniques of each family so that "we test well" stops being an opinion and becomes something you can demonstrate [1][2]. The practical lesson is one: do not ask which one to use, ask how much of each this level of testing needs. The black box tells you whether the software works; the white box, whether your tests really walked through it. The risk lives in the gap between the two.

Sources

  1. ISTQB, Certified Tester Foundation Level (CTFL) Syllabus, International Software Testing Qualifications Board. Describes the specification based techniques (black box: equivalence partitioning, boundary values, decision table, state transition) and the structure based techniques (white box: statement and branch/decision coverage).
  2. ISO/IEC/IEEE 29119-4, Software and systems engineering. Software testing. Part 4: Test techniques. International Organization for Standardization (ISO). Standardizes the specification based, structure based and experience based test techniques.
  3. Myers, G. J., Sandler, C. & Badgett, T. (2011). The Art of Software Testing, 3rd edition. John Wiley & Sons. Reference work that introduces black box and white box testing and their case design techniques.
  4. ISO/IEC 25010, Systems and software Quality Requirements and Evaluation (SQuaRE). System and software quality models. International Organization for Standardization (ISO). Product quality framework on which both testing approaches provide evidence (functional suitability and the other characteristics).

Learn more about AI

See all Learn AI