What are the real pros and cons of each of the main taunts?

see also " What to consider when choosing a mocking structure for .Net "

I am trying to solve a mocking structure for use in a .NET project that I recently started. I would like to speed up my research in different frames. I recently read this blog post at http://codevanced.net/post/Mocking-frameworks-comparison.aspx and wondered if any of the StackOverflow audience has anything to add to the real world benefits. and reservations to the framework.

Can people list the pros and cons of the mocking frameworks that they either currently use or have researched for their own use in .NET projects. I think that this will not only help me make a decision about my current project, but also help others make more informed decisions when choosing the right structure for their situation. I am not an expert in any of the frameworks, but I would like to get arguments for and against the main frameworks that I encountered:

  • Rhinomocks
  • Moq
  • TypeMock Isolator
  • NMock
  • Moles

And other useful alternatives that I missed. I would also like to receive information from users who switched or stopped using products due to problems.

+14
c # moq mocking rhino-mocks
Nov 11 '09 at 22:18
source share
7 answers

I don't know what Moles is, but I will talk about those that I know a little about (I really need a table for this, though).

Moq

Arguments

  • Type safe
  • Consistent Interface
  • Promotes Good Design

against

  • Not as complete as some of its competitors
    • He cannot make fun of delegates
    • He cannot make ordered expectations.
    • maybe other things that I can't think of right now ...
  • It can only simulate virtual / abstract interfaces and elements

Rhino mocks

Arguments

  • Type safe
  • Full feature set
  • Promotes Good Design

against

  • Invalid API. There are too many different ways to do the same thing, and if you combine them incorrectly, it just won't work.
  • It can only simulate virtual / abstract interfaces and elements

TypeMock Isolator

Arguments

  • Security Type (AFAIR)
  • Can mock anything

against

  • Very invasive
  • Lead blocker
  • Does not encourage good design.

NMock

Arguments

  • Promotes Good Design
  • Works on any version of .NET (even 1.1)

against

  • Unsafe type
  • It can only simulate virtual / abstract interfaces and elements

Note that especially the advantages and disadvantages with respect to TypeMock are highly controversial. I posted my own question on my question .

I started with NMock when it was the only option in 2003, and then ported to Rhino Mocks because of its type safety, and now uses Moq because of a simpler API.

+13
Nov 12 '09 at 8:05
source share

So far I have used RhinoMocks and Moq. Moq is currently my favorite because of its simplicity, which is now all I need. RhinoMocks is quite powerful, but I have never been able to fully use it.

+3
Nov 11 '09 at 22:26
source share

We have been using Rhino Mocks for over a year now. PRO:

  • easy to create mocks
  • can mock public and internal methods.
  • can mock interfaces or classes
  • can create partial mocks (make fun of only certain methods from the class)

AGAINST:

  • methods should be at least internal and virtual (can interact with your architecture).
  • It is difficult to use for properties by properties, especially for collections of objects that are created inside the validation area - the syntax of constraints is complicated.
  • You must be careful when recording stops and playback starts.
  • be careful about which calls are made fun of (for example, calling a property that you did not see, or a method that was not virtual) - the errors you may receive are not very useful

As a general note, we found that using fake frameworks helps to test the white box (especially for unit tests). We ended up with tests that confirmed HOW they were done, not what they were doing. They were useless for refactoring, and we had to rewrite most of them.

+2
Nov 12 '09 at 0:34
source share

Like Frank and Chris, I tried RhinoMocks and switched to Moq. I was not disappointed. See my blog post series:

EDIT: Note that I usually test based on state with stubs; I rarely do behavior testing with proven layouts.

+2
Nov 12 '09 at 1:55
source share

I did not use all of these frameworks, but I looked at RhinoMocks and Moq, and went with Moq because it feels more elegant and much simpler. I am using the trunk version, which includes a mandatory fix to limit the 4 arguments to callbacks in the latest beta 4.0.

I especially like the default Moq behavior, which doesn't behave like a strict test with a Mock Object error on unexpected calls. You can configure it for this if you want, but I believe that it takes me too much time to set expectations and not enough time for testing.

+1
Nov 12 '09 at 2:21
source share

I am using TypeMock since I am developing SharePoint. Because TypeMock can mock anything, it has proven to be a valuable resource for unit testing our SharePoint websites, event receivers, workflows, etc.

TypeMock, on the other hand, can be expensive, but there is a version that is specific to SharePoint and costs less than the full TypeMock package. I highly recommend it.

The only thing I disagree with is that TypeMock does not force you to develop code well. Often the classes I create, and the generic code, are well designed. Just because I use TypeMock does not mean that I sacrifice the quality of my design - I still practice IoC and SRP. Just because TypeMock can mock anything doesn't mean that I write my code to reflect this ability.

+1
Nov 26 '09 at 9:55
source share

You can keep in mind that if you need to support a multilingual environment (e.g. VB), all code-configurable frameworks (I can talk directly to Moq and RhinoMocks) will be painful given the (lack of) anonymous delegate / lambda syntax in VB. This will be possible in Visual Studio 2010 / VB 10, but it still will not be comparable to the pretty C # lambda syntax.

TypeMock has specific VB support

0
Nov 11 '09 at 23:05
source share



All Articles