Black-box Tests

Black-box tests are automated tests constructed without knowledge of the software's internal structure. They test what the software is expected to do from an end user's perspective - verifying just the output results given some inputs.

White-box Tests are the opposite of that. They test with a good understanding of the internal workings of the software.

In Unit Testing: Principles and Practices and Patterns, Khorikov argues that since black box tests provide the best resistance to refactoring one of the 4 Pillars of Good Unit Tests, you should aim to write tests in this style mostly. Reserve white box testing to analyse your tests, for example, by utilising Test Coverage Metrics to examine branch or code coverage.


Further Reading

Unit Testing: Principles, Practices and Patterns: Effective Testing Styles, Patterns, and Reliable Automation for Unit Testing, Mocking, and Integration Testing with Examples in C#

Cover for book Unit Testing: Principles, Practices and Patterns by Vladimir Khorikov

This book is one of the most comprehensive guides to automated testing. I highly recommend it. Chapter 4 (pp. 87-90) compares black and box testing in-depth.


Backlinks