Easy way to mock a WCF service?

前端 未结 3 447
清歌不尽
清歌不尽 2020-12-28 23:54

I\'ve got an app which is using a WCF service. Now I\'d like to add unit tests to the app.

For some cases I need to mock the WCF service, since getting the desired b

3条回答
  •  温柔的废话
    2020-12-29 00:26

    You can use any mocking framework like RhinoMocks or NMock, to mock out the interface contract, so if your service implemented IMyService then you could use a mocking framework to set expectations on the method calls on that interface. If you are not familiar with this concept then you can simply create a stand-in object that implements IMyService but pretends to be the real service during your testing. This way when the methods are called they are called on your stand-in object and you can have your stand-in return whatever you want it to.

提交回复
热议问题