Writing testable code
The final aspect we will cover in this chapter is how to write testable code using the SOLID software design principles. As we have seen multiple times already, well-designed code is also easy-to-test code. Application code that is difficult to test is often a sign that the application will be hard to change and maintain.
These five powerful principles were introduced in a paper by Robert C. Martin in 2000, then later published in his book Agile Software Development, Principles, Patterns, and Practices. These principles help Agile teams deliver maintainable, easy-to-refactor code.
Figure 3.5 summarizes the SOLID design principles:
Figure 3.5 – The SOLID design principles
Let us recap the SOLID principles and what they mean for test writing:
- Single Responsibility Principle (SRP): For this, entities should have a single job and a single reason to change. This principle will keep testing code simple since the scope of...