Looking For a .NET Mocking Framework

Posted Wednesday, March 3, 2010 4:42 PM by Kevin

So I've been investigating .NET mocking frameworks to use for unit testing on one of my current projects... A couple of my needs in particular present a special challenge, and I'm looking for any input from experienced mockers out there on what libraries or tools might be available to address my needs.

Specifically, I am working with a third-party API that doesn't use interfaces. In a lot of cases I am deriving from their classes to add additional functionality, but then calling base-class methods in my new implementation. I need to be able to mock the base class for unit testing. The other big thing is that a lot of their API is static methods, so I can't pass a mock object into my implementation. I need something to intercept the static method call and send it to a mock object instead.

I've been reading about Moq, Rhino Mocks, and Typemock. Typemock seems most likely to handle everything I need, but it's rather expensive and I can't seem to find a trial version or anything that will let me prove it will do what I need. So I'm asking the Internet for suggestions! Anyone?

Filed under: , ,

Comments

# re: Looking For a .NET Mocking Framework

Thursday, March 4, 2010 3:46 PM by NoMe

my idea was to use postsharp to wrap it up with a mocking aspect. seems heres an tutorial. havt read but maybe it helps.

jamesryangray.blogspot.com/.../stubbing-static-methods-with-postsharp.html

kind regards

NoMe

# re: Looking For a .NET Mocking Framework

Thursday, March 4, 2010 4:58 PM by Kevin

Thanks for the suggestion!  It looks like this solution requires tagging the classes being marked with a [Mockable] attribute which unfortunately isn't possible in my case (mocking a third-party API that I don't have code for).

The more I look into it, the more it seems Typemock is the ONLY solution for this particular problem.  Maybe someday one of the free options will figure out the magic they're doing.  Meanwhile, I'm going to try out Typemock on one of my personal projects (something that will qualify for the free open source license) and then possibly talk to my boss about making the purchase. :)

# re: Looking For a .NET Mocking Framework

Monday, March 8, 2010 1:16 AM by NoMe

Hi,

Postsharp enables you to weave aspects around calls (e.g. to third party stuff). so i´m convinced its a possible solution for your problem.

have a nice week

kind regards

NoMe