Moq

NMock 2 vs Moq

You may remember from my previous blog post on mocking frameworks that I'm a bit of a fan of this kind of tool. They're great for simplifying unit testing, and can also help guide you in to writing better, more loosely-coupled code via Dependency Injection.

Last night I spent some time porting some of my unit tests for a side project I'm working on from NMock 2 to Moq 4 (currently in beta). My reasons for switching were three-fold: first, NMock can only mock interfaces which was causing problems with testing some parts of my code that relied on elements of the ASP.NET MVC framework; second, NMock is unable to support some of the newer features of .NET as it was written to target .NET 2.0 (whilst each version of Moq is matched to the respective version of .NET, so the Moq 4 beta can utilise the C# 4.0 goodies like dynamic typing); last, the NMock project doesn't seem to be as active as it once was, with the last official build released in January 2008.

As a result of this switch, I'm in more of a position to critically evaluate NMock and Moq than I was when I wrote my original post. Here's a summary of my thoughts and experiences.

Syndicate content