What is the difference between black-box and white-box testing?
Quick Answer
Black-box testing checks behaviour against the spec without looking at the code — you pick inputs from the requirements (equivalence partitions, boundary values). White-box testing uses knowledge of the internal structure to design tests that exercise specific paths, branches and conditions.
Black-box testing means I choose test cases purely from the requirements without caring how it's implemented — I identify the classes of input that should behave the same and test one from each, plus the boundaries. White-box means I look at the code and design tests to hit particular branches and paths I can see. In practice when I write unit tests I know the internal branches, so it's white-box informed, but I still write the assertions against the observable behaviour so the tests survive a refactor.
- Black-box techniques: equivalence partitioning (one input per class of behaviour), boundary value analysis (test at, just below, just above limits), decision tables, state transitions.
- White-box: statement/branch/path coverage, testing each condition in a compound expression.
- Unit tests are usually written white-box-aware (you know the branches) but should assert on behaviour (black-box style).