The textbook treats black box and white box as rival camps, with grey box as a polite compromise. I think that framing is slightly misleading. They are three positions on one slider, the slider being “how much do I know about how this thing works inside?”, and the useful question is which position gives the best return for a given kind of risk. My own view, stated early so you can argue with it: most working testers should spend most of their time at grey.
What each position means
Black box testing treats the software as sealed. You know the inputs you can give and the outputs you should get, as described in requirements, user stories or common sense. You do not know, or deliberately ignore, the code. Techniques such as equivalence partitioning, boundary values, decision tables and state transitions are black-box techniques, since they derive tests from behaviour.
White box testing (also called glass box or structural testing) uses the code itself. You read the branches and loops and design tests to exercise them: statement coverage, branch coverage, condition coverage. Unit tests written by developers are the everyday example.
Grey box sits between. You test from outside, but you use partial knowledge of the internals: the database schema, the API contract, the architecture diagram, the log format, which service calls which. You are not stepping through code; you know enough to aim.
The same feature, three ways
Take a discount rule in an imaginary online pharmacy: orders of ₹1,000 or more get 10 percent off, and orders from first-time customers get an extra ₹100 off, but the total discount may never exceed ₹250.
A black-box tester reads that sentence and designs cases: an order of ₹999 and ₹1,000, first-time versus returning, and a large order where the two discounts would exceed the cap. Nothing in the code is needed. This finds the rule misread, the boundary wrong, the cap forgotten.
A developer working white box looks at the code and sees three branches and a minimum-of function for the cap. She writes unit tests that execute every branch and checks the cap line actually runs. This finds untested paths, dead code, and the branch that a spec-reader would never know existed, say a special case someone added for a corporate account years ago.
A grey-box tester does the black-box cases but also knows that the discount is computed on the server and stored on the order record, and that the invoice is generated by a separate service reading that record. So after placing the order she checks the stored discount value, then the invoice, then the amount sent to the payment gateway. All three must agree. The screen alone would have shown a correct total while the invoice carried a different one.
What each one misses
Black box cannot know which parts of the code it never touched. You can run hundreds of tests and exercise a fraction of the branches, with no signal telling you so. It is also at the mercy of the specification: if the document is silent or wrong, the tests inherit the flaw.
White box is blind to what is missing. Coverage tells you the code that exists has been run; it cannot tell you that a required rule was never implemented. Full coverage of a program that omits the cap rule is still full coverage. White-box tests also tend to mirror the author’s assumptions, because the person who wrote the code writes the tests that confirm it.
Grey box can drift into either mistake. Knowing the internals can make you over-trust them (“the database column is not null, so it cannot be empty”) or lead you to test how the system is built rather than what the user needs.
| Viewpoint | Strong at | Weak at | Usually done by |
|---|---|---|---|
| Black box | Missing or misread requirements, user-visible behaviour | Knowing what code was never exercised | Testers, business users |
| White box | Untested paths, logic errors in branches | Missing features; shared assumptions | Developers |
| Grey box | Integration and data consistency, targeted risk | Can inherit assumptions from the design | Testers with technical knowledge |
Taking a side
Pure black box is an admirable ideal and a poor daily habit. Ignoring information that is freely available is not rigour; it is waste. If you know an order passes through a queue, you know to test what happens when the queue is slow. If you know there is a nightly job that recalculates balances, you know to place a transaction just before it runs. Those tests come from knowledge of structure, and they find the bugs that matter in connected systems.
Equally, I would not ask most testers to read code branch by branch. That is a developer’s job, it is more efficient at unit level, and a tester doing it is usually doing it worse than a good unit test would. Where testers gain from reading code is lightly: reading a pull request to spot what changed and what it touches, which is a grey-box activity wearing a white-box coat.
There is a fair counter-argument. Independence is valuable. A tester who knows too much about the implementation may stop asking naive questions, and naive questions find the oddest bugs. Fresh-eyes black-box sessions, with a new joiner or a business user, have a place for exactly this reason. The best teams schedule both: informed testing for depth, uninformed testing for surprise.
Choosing in practice
Match the viewpoint to the risk. Worried about requirements being met from a customer’s side? Start black. Worried about complex logic with many branches, such as a tax or pricing engine? Push for white-box coverage at unit level and check the coverage report for untouched branches. Worried about integrations, data flowing between services, or the database ending up consistent? Go grey. Many real bugs, from a stored value disagreeing with the displayed one to a message published twice, are visible only when you look behind the screen.
One more point on terminology. Some sources link these terms to levels (white box for unit testing, black box for system testing). That is a common pattern, not a rule; any level can be tested from any viewpoint. And grey box has no single official definition, so when a colleague uses it, ask what they mean before you assume.
Figures and names in the examples are illustrative.
Leave a Reply