Applying SOLID principles to unit testing
The SOLID principles are highly covered and advertised on the web and in books. Chances are that this is not the first time that you’ve heard or read about them. They are a popular interview question as well. SOLID principles stand for the following:
- Single-responsibility principle
- Open-closed principle
- Liskov Substitution principle
- Interface Segregation principle
- Dependency Inversion
In this section, we are interested mostly in the relationship between the SOLID principles and unit testing. While not all the principles have strong ties with unit testing, we will cover all of them for completion.
Single-responsibility principle
The single-responsibility principle (SRP) is about having each class with one responsibility only. This will lead it to have one reason to change. The benefits of this approach are as follows:
- Easier to read and understand classes:
The classes will have fewer...