How do I mock a class without an interface?

前端 未结 8 1272
[愿得一人]
[愿得一人] 2020-11-30 23:50

I am working on .NET 4.0 using C# in Windows 7.

I want to test the communication between some methods using mock. The only problem is that I want to do it without i

8条回答
  •  爱一瞬间的悲伤
    2020-12-01 00:21

    The standard mocking frameworks are creating proxy classes. This is the reason why they are technically limited to interfaces and virtual methods.

    If you want to mock 'normal' methods as well, you need a tool that works with instrumentation instead of proxy generation. E.g. MS Moles and Typemock can do that. But the former has a horrible 'API', and the latter is commercial.

提交回复
热议问题