Use Available Facilities
This is frequently expressed as “test through the interface.” In the general sense, the statements are equivalent, but object-oriented programming languages have also given us a narrower interpretation that is not sufficient. This principle is broader than simply using the methods declared in an interface.
When writing tests, we want to minimize the degree to which we change the code under test to accommodate testability. The best way to do that is to use the features that already exist. This may be obvious for constructors, setters, and getters and completely natural and necessary for method arguments, return values, and other direct functionality. I have often seen other features of the code overlooked as potential ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access