Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why would I select Moles as my mocking framework?

I've been looking at several Mocking frameworks for ASP.NET and came across Microsoft Moles. This seems to be a part of Microsoft Research team and was wondering If anyone here has selected Moles over other matured Mocking frameworks such as Moq.

like image 573
user300981 Avatar asked Jun 14 '10 02:06

user300981


2 Answers

I actually use Moq and Moles in the same test project. Both have strengths and I use each where appropriate. Generally, I use Moq for the standard sort of AAA testing with verification, and Moles is the 'big gun' for the otherwise unmockable things, like extension method calls etc.

I like this arrangement, because each test can be as simple and sensible as possible, even though the mocking setup might vary a lot from test to test.

like image 163
ZeroBugBounce Avatar answered Oct 24 '22 09:10

ZeroBugBounce


Moles was designed to work efficiently with the white box analysis of Pex. All other mock framework usually incur a lot of overhead.

Moles provides a simple value proposition: replacing any .NET method with a delegate. By design, Moles does not provide any API to express 'verification' as other frameworks do. It is really up to you to decide whether this decision suits your or not.

If you need to deal with (legacy) code that depends on hard-coded static methods or sealed types with internal constructors, Moles can help you deal with these cases.

If you have interfaces and nicely componentized code, Moles also generates slim stubs, i.e. interface implementation, that you can use with the profiler.

like image 5
Peli Avatar answered Oct 24 '22 11:10

Peli