Switching to Moq

10/06/08

Permalink 07:11:08 pm, by truewill Email , 221 words, 281 views   English (US)
Categories: Testing, .NET, Tools

Switching to Moq

I converted the unit tests on my current project to use Moq instead of Rhino Mocks today.

Daniel Cazzulino gave me the last piece of the puzzle on the discussion group: Mock.Get(theInterface) returns the mock for the given interface instance, allowing me to set further expectations on an object. See the discussion for the reasons I wanted this feature.

The only major issue I ran into in converting the tests was one class that used out parameters on methods. Since Moq doesn’t support out or ref parameters in the current revision (it’s supposed to be in the trunk, though), I created a stub class by hand in a few minutes. Hopefully I can remove that in the near future.

It’s liberating to have no record/replay model. I also find Moq relatively intuitive; with Rhino Mocks, I regularly had to look up how some feature worked.

No one I asked at work had used either library, so I was free to switch. I plan to do a presentation on Moq to the developers in the near future.

Update - October 8, 2008

A new version of Moq is available with support for out and ref parameters! I tested it with out parameters, and it works. You do have to be careful due to closures capturing variables, though - please see the discussion posts.

Comments, Pingbacks:

No Comments/Pingbacks for this post yet...

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))
The name truewill is composed of two other words. What is the SECOND word?

Development Central

Development Central is the blog of Bill Sorensen, a professional software developer. Much of this will relate to C#, .NET, and OOP in general.

Disclaimer
These postings are provided "AS IS" with no warranties and confer no rights.

Search

Categories

Linkblog

b2evolution

contributors

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 3

powered by b2evolution free blog software