Follow @RoyOsherove on Twitter

Choosing a Mock Object Framework

Update:

I've added a simple Poll at the bottom of this post which you can answer on your most used frameworks.

-----------------------

My upcoming book is going forward ever so slowly, mostly due to my beautiful new son, Itamar, which seems to be changing everyone's priorities, by simply being the cutest little person that he is (at 4 months).

Still, I'm struggling to bring myself to write more, and it's a tough job. I simply feel less strongly about everything technical these days, but it's slowly coming back to me.

I'm currently struggling with Chapter 5, which is currently titled "Mock Object Frameworks". My current dilemma is a pretty important one, so I thought maybe you guys can help me with directions on my decision.

My question to you: Which Mock Object framework should I use for Mocking examples in my book?

There are my current candidates:

1. NUnit.Mocks (yes, there is such a thing! here's an example)

Simple, Easy, and straightforward, this feels like the perfect framework to start the novice Mocker off with, especially since NUnit plays a role earlier in the book. However, I'd also like to show later on more advanced stuff that NUnit.Mocks does not support like events, generics etc, which other frameworks do. I'm not sure how great I feel about changing the mock framework from underneath the reader's nose mid way... what do you think?

 

2. NMock

This is one of the "standard" frameworks for mocking in .NET, and many people use it, but it's getting old. It has a new version Nmock2, which I'm considering, but that hasn't been updated in over a year (see next bullet)

3. NMock2

Looks very promising, and sounds great, but the Downloads section of SourceForge seems to only have a version from May 2006, a year ago! Does anyone know what' sup with this framework's code? Is it actively maintained? It has a continuous build cycle, I know, but is it actually progressing somewhere? I wouldn't want to write about a framework that's on it's way out one way or another. Thoughts?

4. EasyMock

One of the "Standards". I like it. it's nice and easy, but some things are missing (that I'm missing from it, at least. Maybe they are there?) - Support for checking parameters with custom matchers (assert that the parameter passed in contains some string, for example, or check a property value on a passed in object).  Plus, it's latest version is very old from 2004.

5. Rhino Mocks

Oren Eini is doing a great job with this framework, and I think it's the only one that seems to be keeping up with the latest features in .NET, other than TypeMock. Plus, it's totally free to use (as are all the previous ones). It's also the only one other than TypeMock which does not require you to input strings for method names you'd like to mock, which is cool. It's compelling to use it but the project is currently maintained by just one person. If Oren decides to drop it, or for any reason stop working on it, the book might turn out outdated quite quickly. Plus, it's not very widely used, though it seems to be gaining in popularity.

6. TypeMock

Great framework, with lots of features. No need to use strings for method names like in RhinoMocks. Also, not very widely known, but gaining in popularity quickly, mainly because of it's ability to mock anything including statics, privates and events, without even requiring you to inherit or implement any interfaces or virtual methods. It's almost magical in that sense(or even too powerful), but it also support the "traditional" way of mocking objects, just like all the others. Sadly, it's Commercial, and I'm not sure how well that would be received by my readers.

 

What do you guys think? What framework is a good fit for a book about Unit Testing and Mock Objects?

Write a comment, or take this quick Poll:

Poll: What Mock Frameworks do you use?

How I got over my Ego