33.9. SummaryWe have strongly advocated that Fit tests express the business rule tests as clearly as possible. This may seem difficult to do because it is so easy to get caught up in the way things are, or will be, implemented, instead of the essence of what's needed from a business perspective. It may also seem strange because it seems like rework, with the application having to change to aid testability. We have seen how we can, step by step, eliminate dependencies that get in the way of testing. In the previous chapter, we started by rejecting the idea of testing through the UI explicitly in the Fit tables and showed how the fixtures could act as adapters to do that job. We then looked at how to eliminate or reduce dependencies between the domain objects and the presentation and the data source layers and other domain objects. The adaptation of the application to enable testing needs to be done carefully, so as to minimize the risk of lowering quality. As tests are introduced from the outer level, the UI, they can support refactorings that enable still more test access. There may be complex internal logic that is dependent only vaguely on the business logic and so will not be tested with the Fit tables. In that case, the process of adaptation needs to continue deeper into the application, with the support of programmer tests, such as in JUnit. The changes we need to make to enable direct testing have huge benefits in other respects. Making a system testable for business-oriented tests and for programmer tests leads to strong modularity and a reduction in redundancy. It is not uncommon to add functionality to well-structured software by generalizing and shrinking the code. Experience has shown that driving the development of the code with tests, at the business and programmer levels, can lead to high-quality systems that continue to be refreshed as they change. Doing a little refactoring all the time, as a part of the design process, can mean that development goes more quickly rather than more slowly. The reason is that much less effort is spent in bug fixing and rework, and it is much easier to enhance good-quality code. Questions & Answers
|