Integrate Pex with MoQ

廉价感情. 提交于 2019-11-30 07:55:41

Pex uses Moles for isolation (mocking). One can still use MoQ alongside Moles. It's actually preferred to use a framework like MoQ for stubbing and mocking when the code can allow for it, leaving only Moles for the stuff MoQ can't isolate (sealed classes, non-virtual methods, private members, etc).

To backup my statements, Peli de Halleux (a member of the Pex and Moles project), mentions doing the same thing over on MSDN forums.

I have been using Moles and you can code with both frameworks in a unit test. But this probably isn't much help as you are asking specifically about Pex, which I haven't tried yet. Is it possible to modify the unit tests Pex creates and add the MoQ code after the fact?

When writing parametrised Pex tests make sure that when you get those "Uninstrumented methods" related to Moq calls, you can easily click on "Ignore uninstrumented method..." that will add assembly attribute to your test project and it will simply ignore Moq methods thus making them usable in your tests.

I've done it myself and tests run as expected.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!