Key takeaways
- Black box focuses on inputs and outputs and suits testers and acceptance work.
- White box focuses on code paths and suits developers and unit testing.
- Grey box uses partial knowledge such as the database schema or API design.
- Coverage measures how much code tests exercise but not whether tests are good.
- Use both views for stronger results.
What is black box and white box testing?
What is black box testing?
In black box testing the tester treats the system as a box whose inside cannot be seen. Tests come from requirements, user stories and specifications. The tester gives inputs, observes outputs and compares them with expected behaviour. This view matches how users experience the product, and it works at every level from component to acceptance.
Which black box techniques are common?
Equivalence partitioning groups inputs that should behave the same, so one value represents each group. Boundary value analysis checks values at the edges of ranges. Decision tables list combinations of conditions and results. State transition testing checks how the system moves between states. Use case testing follows user scenarios. Error guessing relies on experience of typical faults.
What is white box testing?
White box testing uses the internal structure: code, branches, loops and data flow. Developers usually perform it at unit level. The goal is to make sure that each part of the code is exercised and that logic works for different paths. It can find hidden errors that behaviour-based tests miss.
What coverage measures are used?
| Coverage | Meaning |
|---|---|
| Statement | Share of statements executed |
| Branch or decision | Share of decision outcomes (true and false) executed |
| Condition | Each condition in a decision tried both ways |
| Path | Share of independent paths executed |
| Higher coverage is useful but is not proof of quality. A test can run a line without checking its result. |
Can I see a small example?
function grade(score):
if score >= 90: return "A"
elif score >= 60: return "B"
else: return "C"
For branch coverage you need at least one test per outcome: 95 for A, 70 for B and 40 for C. A black box tester would add boundary values 89, 90, 59 and 60 from the requirement, which also reveals if the code uses the wrong comparison.
What is grey box testing?
Grey box testing uses partial knowledge of internals, for example knowing the database tables to verify stored data after a UI action, or knowing API contracts to design tests. It combines the user viewpoint with some structural insight, and is common in integration and API testing.
How do the approaches compare?
| Aspect | Black box | White box |
|---|---|---|
| Knowledge of code | Not needed | Required |
| Based on | Requirements | Code structure |
| Typical testers | Testers, users | Developers |
| Typical level | System, acceptance | Unit, integration |
| Finds | Missing or wrong behaviour | Logic and path errors |
When should I use each?
Use white box methods to protect logic-heavy code and measure unit test coverage. Use black box methods to confirm that requirements are met and to find usability and workflow problems. Use grey box methods when you test services and databases. A mix gives fewer blind spots.
What mistakes appear most often?
Chasing a coverage number without meaningful assertions, ignoring requirements when reading code, and assuming testers need no technical knowledge. Review tests as carefully as code.
How do I practise both approaches?
Take a small function with several branches, such as a shipping fee calculator. First, write black box tests from a written rule list using partitions and boundaries. Then read the code, draw its branches and add tests for any path that is not yet covered. Compare the two sets and note which defects each style would have found. This exercise teaches why interviewers expect testers to understand both views and gives you a concrete example to describe in an interview.
What is a quick checklist for choosing an approach?
Ask whether you have access to code, whether the goal is to confirm requirements or to protect logic, which level you are working at and what risk you want to reduce. Then pick techniques accordingly and record the reason in your test notes.
What is a sample interview answer?
"Black box testing checks behaviour from requirements, white box testing uses code structure, and I combine them: boundaries from the spec and coverage from the code."
Download Black Box and White Box Testing PDF
Black Box and White Box Testing PDF
The PDF carries the same content as this page in a clean, print-ready layout, so you can read it offline and keep it for revision.
4 pages · 103 KB · PDF · Updated 5 Nov 2026