Are Using Interfaces Soley to Facilitate Stubing and Mocking in Unit Tests Now Obsolete?

后端 未结 4 833
既然无缘
既然无缘 2020-12-29 09:28

In .NET, TypeMock Isolator and Microsoft Moles allow one to isolate any class, property, or method - be it sealed, static, protected or non-virtual. So what was impossible t

4条回答
  •  失恋的感觉
    2020-12-29 09:54

    Not at all. From a purely technical point of view the interfaces are not strictly necessary. The only requirement for a mocking framework to construct a mock is that a method is virtual and the type has an accessible constructor. I utilize it quite a bit when I know that a particular class will not have multiple implementations.

    I prefer doing TDD with a normal Castle Dynamic Proxy based mocking framework. It is all about creating a loosely coupled system with appropriately placed testing seams. Those testing seams could in future become extensibility points. The requirements placed by mocking considerations reinforce good design practices, causing more focused classes to be written.

提交回复
热议问题