Black box vs white box testing
Black box testing derives its tests from what the software is specified to do, without looking at how it is built. White box testing derives its tests from the internal structure of the code. Black box tests can show that a required behaviour is missing, and white box tests reach code that no requirement mentions.
The longer version
A function that decides whether a year is a leap year shows both approaches on a few lines of code. The rule it must implement has three parts: a year divisible by 4 is a leap year, a century year is not, and a century year divisible by 400 is one after all. A black box tester works from that rule and never opens the code. Four inputs follow from it: 2024 should be a leap year, 2023 should not, 1900 should not and 2000 should. A white box tester opens the code and finds two decisions, one on divisibility by 4 and one on divisibility by 100. Three inputs, 2023, 2024 and 1900, take both decisions each way, so every branch has run and every result is correct. The code contains no check of divisibility by 400. The white box tests cannot show that, since there is no branch to cover, and they report full branch coverage on a function that gets the year 2000 wrong. The black box test for 2000 fails at once.
The reverse case is as easy to build. Suppose the developer added a branch nobody asked for, one that returns an error for any year below 1. Nothing in the rule mentions it, so no black box test is derived for it, and the branch ships untested unless somebody reads the code. The ISTQB Foundation Level syllabus, version 4.0.1, describes this trade in general terms. Black-box techniques, also called specification-based, "are based on an analysis of the specified behavior of the test object without reference to its internal structure", so the test cases stay useful if the implementation changes while the required behaviour stays the same. White-box techniques, also called structure-based, "are based on an analysis of the test object's internal structure and processing", and can only be created once the design or the implementation exists. The syllabus names the shared strength of white-box techniques as taking the entire implementation into account, which helps even when the specification is vague, outdated or incomplete. It names the weakness too: where the software does not implement a requirement, white-box testing "may not detect the resulting defects of omission".
Each approach has techniques and a measure of its own. For black box testing the syllabus teaches equivalence partitioning, boundary value analysis, decision table testing and state transition testing, each of which turns a specification into a small set of cases. For white box testing it teaches statement testing and branch testing, whose results are coverage figures. The syllabus points out that performing only black-box testing gives no measure of actual code coverage, which is the gap white box measurement fills. It classes both as test types that can be applied at all test levels, so pairing white box with unit tests and black box with acceptance tests is a common habit that the definitions do not require. A third family, experience-based techniques, draws on the tester's knowledge and is presented as a complement to the other two. Grey box testing sits between the two boxes. The ISTQB glossary defines it as a test approach that combines elements of black-box testing and white-box testing: the tester knows something of the internals, such as the database schema or an API contract, and still drives the test from outside.
Set side by side, the two differ on six points. The basis is the specification for black box testing and the code or design for white box testing. The knowledge needed is the domain and the requirements for the first, and the programming language and the structure of the code for the second. Black box tests can be designed as soon as a specification exists, while white box tests wait for a design or an implementation. Black box coverage counts items from the specification, such as partitions and boundary values, and white box coverage counts statements and branches. Testers, analysts and users mostly work black box and developers mostly work white box, a division of habit and not of definition. The tools follow the same split: browser and API automation drive black box tests from outside, and a unit test framework run with a coverage tool serves white box tests. Other names are in use: closed-box or opaque-box testing for the first, and clear-box, glass-box or structural testing for the second. Security testing uses the same pair. A black box assessment attacks the running application with no inside knowledge, and a white box review reads its source code and configuration.
Common questions
Black box vs white box testing: what is the difference?
Black box testing designs tests from the specification and judges the software by its inputs and outputs alone. White box testing designs tests from the code and judges them by how much of its structure they exercise. A black box test stays valid when the code is rewritten, while a white box test is tied to the implementation it was written against.
What are the advantages and disadvantages of black box and white box testing?
Black box testing checks the software as its users meet it, needs no access to the code, and finds required behaviour that was never built, but it cannot tell which code its tests reached. White box testing shows exactly which statements and branches ran and reaches code no requirement mentions, but it needs programming knowledge, breaks when the code is restructured and cannot see a missing requirement.
Who performs black box testing and who performs white box testing?
Black box testing is usually done by testers, business analysts and, in acceptance testing, by users, since it needs knowledge of what the software should do. White box testing is usually done by developers or by testers who read code, since it needs the source and an understanding of its structure. The ISTQB syllabus defines both by how the tests are derived, so the split by role is a habit and anyone can apply either.
What is black box testing?
Black box testing is testing in which the tests are derived from what the software should do, with no reference to its internal structure. The ISTQB glossary defines it as a test approach based on the specification of a component or system, and gives specification-based testing as a synonym. Equivalence partitioning and boundary value analysis are two of its techniques.
When should a team use black box testing and when white box testing?
Black box testing fits wherever there is a statement of required behaviour to test against: requirements, acceptance criteria or an API description. White box testing fits where the code is open to the person testing, and its use is to find the parts no existing test runs. The first asks whether the software does what was asked, and the second asks what in the code is still unexercised.
Can black box testing measure code coverage?
Black box testing alone gives no measure of code coverage, a point the ISTQB Foundation Level syllabus makes directly. Its own coverage is counted in items taken from the specification, such as the equivalence partitions or boundary values that have been tried. A coverage tool run during black box tests will still report which code they reached, and reading that report to add tests is white box work.
Where does grey box testing fit between black box and white box testing?
Grey box testing uses partial knowledge of the internals to choose tests that are still run through the external interface. The ISTQB glossary defines it as a test approach that combines elements of black-box testing and white-box testing. A tester who knows that search results are cached for a minute, and edits a record inside that minute to see which version the page shows, is working grey box.
Bug reports that arrive ready to triage.
Collect replay, console, network and browser context with the Free plan.