RhinoMock vs TypeMock vs NUnit Mocking?

I'm just starting to work on Test Driven Development, and I wonder what are the main differences between RhinoMock, TypeMock and NUnit that are mocked?

Any information would be greatly appreciated!

+19
unit-testing nunit mocking rhino-mocks typemock
Sep 04 '09 at 13:23
source share
4 answers

TypeMock is a commercial product (which means you have to pay for it), but will allow you to mock specific objects - unlike RhinoMocks / NUnit / MoQ, which can only mock an interface / abstract class. How this is achieved is borderline black magic, but it does some very smart things with the CLR.

This can be especially useful if you use libraries in your project that do not use many interfaces. Thus, you could, for example, use TypeMock to mock LINQtoSQL datacontext or Sharepoint objects. However, if you use TypeMock, this is no excuse for poor design in your application .

As far as I know, in addition to minor differences in syntax, most of the mocking frameworks have moved away from the old recording / playback model. Typically, you customize your layouts by naming expectations using the Fluent Interface.

Personally, I used only MoQ and I <3 it.

+35
Sep 04 '09 at 13:50
source share

A video called TDD - Understanding Roy Osherove's Mock Objects is very helpful in exploring the differences between different mocking libraries. He does not understand every aspect in detail, but enough for you to understand. Hope this helps. Roy is also the chief architect of TypeMock and is a very influential figure in the testing arena. I can’t recommend this video enough for anyone who wants to learn how to use mockery and also learn about the available libraries.

The main difference between TypeMock and the open source library is that TypeMock uses the Profiler API provided by Microsoft, instead of a dynamic proxy server . This allows TypeMock to mock specific classes and static methods. If you do not know what a profiler is, this is the same API that is used by tools such as JetBrain dotTrace and RedGate Ants.Net Profiler. TypeMock just uses the API in a different way to fake (layout) what you tell it.

@RichardOD, thanks for the reminder, his book " The Art of Unit Testing" describes in more detail where there is no video. I have a book, and it is very informative.

+18
Sep 04 '09 at 14:02
source share
  • Rhino.Mocks is one of the most successful developers in the industry, an open, constantly developed and improving interface. It has been a while and therefore supports quite a few different paradigms for ridicule. It can be a little harder to learn, therefore, in the sense that you can find tutorials for the β€œold” way of doing things. Here the tips, SetUpResultFor () and Expect.Call () , are old ways of doing things. New way: mockObject.AssertWasCalled () .

I had no personal experience with these others, but ...

  • MOQ is an open source, constantly improving and improving the infrastructure of one of the most diverse developers in the industry (compared to Ayende). It is newer and therefore does not have some of the features that Rhino.Mocks has. This is usually not a problem, as these functions are usually those that are somewhat outdated in Rhino. I heard that it’s a little easier to learn because of this (mocking frameworks, by the way, are not difficult to learn).
  • NUnit Mocks is very strange as far as the mockery goes. It does not currently support the preferred Arrange-Act-Assert syntax, which instead relies on Expect-Verify (record / play). It also relies on strings to define method names and properties instead of lambda. This makes it significantly resistant to refactoring. This is a serious problem. I would not recommend it.
  • TypeMock Isolater - company hardcore for fraudulent fraud (owned?) Roy Osherow is a guy who knows his testing, but also has somewhat mildly conflicting opinions on how to use it. It is really intense as far as it can do - going down to a low level and changing the operation of CLR objects. The philosophy behind TypeMock is not really 100% TDD. Part of the benefits of TDD is that, covering the limitations of Mocking frameworks, you will develop better code. TypeMock explodes these restrictions into pieces. As far as I know, they are mainly used by people who are trying to get code that they do not have control over testing.
+14
Sep 04 '09 at 15:59
source share

I use TypeMock all the time and consider it a very powerful tool that can improve the coverage of my unit tests. This is because I work with SharePoint, and only TypeMock allows me to mock SharePoint classes because they are specific classes, not interfaces.

Lubrication of SharePoint classes is not possible with RhinoMock, Moq, NUNit, etc., because (I believe) they need interfaces to mock objects, and not the ability to mock specific concrete classes.

If your code really uses many interfaces, and you don’t need to mock specific classes, then TypeMock is a bit expensive, but it's worth it to get the power.

+2
Sep 04 '09 at 14:03
source share



All Articles