Black, white and grey box testing
The three methods describe how much you know about the code while you test. Most QA work is black box, but knowing a little about the inside helps you find bugs faster.
At a glance
| Method | You know | Usually done by | Typical example |
|---|---|---|---|
| Black box | Only inputs and outputs | QA, product, users | Sign in with a valid and an invalid password |
| Grey box | Some internals: API, database, logs | QA | Create an order in the app, then check the API response and the stored record |
| White box | The source code | Developers | Unit tests that cover every branch of a function |
Black box testing
You treat the app as a closed box. You give it input, watch what comes out and compare it with the requirements. You don't need to read any code.
- Based on: requirements, user stories, designs and how real users behave.
- Good at: finding missing features, wrong behavior and confusing flows.
- Blind spot: code paths you can't reach or can't see from the UI.
Requirement: a coupon code gives 10% off orders over $50.
Test: order of $60 + code SAVE10 -> total $54.00
Test: order of $40 + code SAVE10 -> error "Order must be over $50"
Test: order of $60 + code save10 -> is the code case-sensitive? Check the spec.
White box testing
You read the code and design tests that exercise its paths: every if, every
loop, every error handler. This is mostly what unit tests do.
- Based on: the source code and its structure.
- Good at: dead code, unhandled branches, off-by-one errors and missing error handling.
- Blind spot: features that were never built. You can't cover code that doesn't exist.
Coverage terms you will hear
- Statement coverage: every line ran at least once.
-
Branch coverage: every
ifwent both ways, true and false. - Path coverage: every combination of branches ran. Rarely practical.
Grey box testing
You test from the outside like a user, but you use what you know about the inside to pick better tests and check results more closely. This is where QA adds the most value.
- Watch the network requests while you use the app.
- Check the database, logs or analytics events after an action.
- Change data directly to reach a state that is hard to reach from the UI.
- Read the API docs to find fields and limits the UI doesn't show.
Test: change the profile name to "Ana Lúcia"
UI: new name shows on the profile screen
Network: PUT /profile returns 200 with the new name
Logs: no warnings about encoding
Reload: name is still correct after closing and reopening the app
To get started, see Network debugging, Storage and cookies and Platform tools & ADB.
Which one to use
- Start black box: does it do what the user and the spec expect?
- Go grey box when something fails, or when the UI hides what really happened.
- Leave white box to the developers, and ask what their unit tests already cover.