This is the final post in my series on OOD class principles and testability. It has included:
There was a pit stop at YAGNI and Testability as it had some bearing on the OCP. It was all kicked of by Benefits of Testability. Which was inspired by Dr. Stefan Jungmayr’s dissertation Improving testability of object oriented system.
Here is a table that I think quickly summarizes how, when followed, the principles relate to the three aspects of testability.
|Single Responsibility Principle||Yes-less||Yes-less||Yes-less|
|Interface Segregation Principle||Yes-less /w doubles||Yes-less /w doubles||Yes-less /w doubles|
|Dependency Inversion Principle||Yes-less /w doubles||Yes-less /w doubles||Yes-less /w doubles|
|Open Closed Principle||Yes-less /w doubles||Yes-less /w doubles||Yes-less /w doubles|
|Liskov Substitution Principle||No||No||Yes-reuse|
|Law of Demeter||Yes-less||Yes-less||Yes-less|
Yes-less = Because the surface area and or type population of the test subject has been reduced, there is less to: observe, control, or understand.
Yes-less /w doubles = The benefits of Yes-less are gain only by using test doubles (e.g. mock) and interaction based testing.
Yes-reuse = Because test fixtures can be reused to test all subtypes.
After studying the table I noticed two things. It pays to have less to work with in a test. That is to say that when there are very few types and members involved in a test it will be easier to understand. It is easier to observer and control less than more. When you can’t have less it pays to have a test double.
It seems there two general fulcrums that you have to control testability. They are decreasing the surface area and type population or introducing test doubles. As well, they help in increasing the effectiveness of unit tests by eliminating failure points other than the test subject.4,993 Total Views