Black-box testing
Тестирование чёрного ящика
This approach checks what software does from the outside: give it an input or perform an action, then compare what you observe with what should happen. Tests are based on expected behavior rather than on how the code is written.
Also known as: white-box, белый ящик
What makes a test black-box?
A black-box test exercises a system through an interface and checks behavior defined by a requirement, acceptance criterion, or documented contract. The interface might be a function, an HTTP API, or a user interface. What matters is how you chose the cases and their expected results, not whether you can open the source code. A developer who wrote the feature can still design a black-box test for it.
How to choose test cases
Start with a rule you can turn into a specific expectation. Set up any required starting state, perform the action, and check the result. That result can include a visible side effect: a successful response alone doesn't prove that an item was actually saved.
- Equivalence partitioning groups inputs by expected behavior. If a rule rejects all negative quantities, you can sample that group instead of trying every negative integer.
- Boundary value analysis checks values at and around the edges of a range, where off-by-one errors often show up.
- State transition testing checks actions in sequence when the same action can have different outcomes depending on what happened before.
Example: canceling an order
Suppose the API contract says a pending order can be canceled, but a shipped order cannot. Create a pending order, cancel it, then read it through the API and verify that its status is canceled. In a separate test, start with a shipped order, attempt cancellation, verify the documented error, and read the order again to make sure it still shows shipped. Checking the database table directly isn't necessary: the contract tells you what to expect, and the public API gives you a way to observe it. If the contract doesn't say what happens on a second cancellation request, clarify that rule rather than treating the current implementation as the expected answer.
Where it fits
Black-box testing is a way to design tests, not a test level. It can be used in a unit test of a public function, an integration test across a service boundary, or an end-to-end test of a customer workflow. Tests tied to a stable contract can keep working after the underlying code is refactored.
White-box testing is a different approach, not a synonym. It uses knowledge of the implementation to target structures such as branches. A set of black-box tests can exercise many branches without deliberately targeting them. Likewise, knowing that both sides of an if ran doesn't tell you whether the tests checked the right business outcomes.
In interviews
Expect a small requirement and a prompt like “How would you test this?” State your assumptions, pick representative cases, and give a concrete expected result for each. If an action changes state, explain how you would verify that change through the interface.