ProAnswers.org

Recommend good C# mocking framework?

I want to start using mock objects on my next C# project.

After a quick Google search I’ve found there are many:

•NMock
EasyMock.NET
•TypeMock Isolator Commercial / Paid
•Rhino Mocks
•Moq
•NSubstitute
•JustMock Commercial / Paid
•FakeItEasy

So recommend which one is helpful for my project?

I’ve not used most of the ones you’ve listed, so I can’t be objective about it, but I use Moq and it has been awesome. The fluent interface makes it a joy to work with. For example:

mockService.Expect(s => s.GetCustomers()).Returns(new List<Customer>());

@Ngu Soon Hui, I wasn't aware that the other frameworks don't have compile-time checking. Moq certainly does. In my example above, if the service class that mockService is mocking doesn't have a GetCustomers() method, I would get a compile-time error. I'd also get one if the GetCustomers() method didn't return a List or an interface like IList.