Ideally, all software should be tested. That said, some designs are more easily tested than others. This “testability” factor can be very useful in determining the quality of a given design. Here are some reasons.
- When a design is excessively coupled, then testing any class in it will require that many other parts of the system be created in the test. This can make tests complex to write and slow to run. The test will also fail for multiple reasons.
- When a class has multiple responsibilities (weak cohesion) then those responsibilities must be tested together. The tests become difficult to read, write, and maintain.
- When the system has redundancies, the tests will too because the same issues will have to be tested repeatedly.
- When encapsulation is weak many side effects are possible and, therefore, tests must be written to guard against them. The test suite becomes many times larger than the production package.
Testability is really the quality of all qualities because weakness in design always makes testing difficult and painful. And after all, pain is nature’s diagnostic tool. We feel pain in order to know that something is wrong.
The earlier testability is considered, the earlier design flaws can be discovered and corrected.
This is Scott Bain. Visit us at www.netobjectives.com.