开发者

Why is mocking preferred with Interfaces?

I have been looking at examples of mocking 开发者_Python百科using Moq and Rhino Mocks and all the examples seem to mock interfaces. Why is this? I have heard they can mock static classes, but what about non-static classes?


Because:

  1. All methods on your object would need to be virtual in order to mock them
  2. Your mock would still need to execute the constructor of the real object, pass parameters and run the logic inside it, which can be painful.


Because that was limitation of DynamicProxy (used to create instance of the mock object). Will be no problem if you using interface, but If you want to use class then you should make all public member virtual. http://tiredblogger.wordpress.com/2008/05/06/moq-mocks-use-virtual-method-or-interfaces/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜