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 hooks to support testability. Logging, monitoring instrumentation, factories, dependency injection, callbacks, and template methods all provide vectors through which to exercise greater control over the code under test. In the interest of containing complexity and preserving the intended design, existing facilities should be used before creating new ones.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.246.245