Contrary to most beliefs, even if you are conducting Test-Driven Development (TDD), you should still follow good design practice. The trick is to make the API testable and well-designed. TDD is not a design methodology , but a feedback method.
Therefore, this is not a matter of the Mocks interface versus the Mocks subclass, but rather a matter of interfaces and subclasses.
This is a really old discussion, which was supposed to end in 1994; in Design Patterns , we learn that we need to maintain composition over inheritance .
There is a long discussion of this topic, but, in short, in languages ββwith one inheritance, based on the design of the inheritance API, it is necessary to limit all future variability to other (but unforeseen) dimensions. Inheritance in such languages ββis simply too restrictive. Since all major object-oriented languages ββ(Java, C #, Ruby) have one inheritance, you should see that most object-oriented code bases avoid inheritance correctly.
When a design is based on composition over inheritance, it follows that if you use mock objects, you will mock interfaces, not base classes.
source share