Mocking classes that aren't interfaces

前端 未结 3 1088
无人共我
无人共我 2020-12-11 17:37

I\'ve been writing some providers in c# that inherit from the providerbase class. I\'ve found that it\'s hard to write tests that use the providers as most mocking framework

3条回答
  •  暖寄归人
    2020-12-11 18:16

    RhinoMocks or Moq will create test doubles for classes as well as for interfaces. The type has to have virtual methods or be abstract though. The Typemock isolator gets around this.

    I'd suggest that the objects you want to mock probably should be abstract (dependency inversion principle).

提交回复
热议问题