BT

Moq .NET Mocking Library

by Al Tenhundfeld on Aug 12, 2008 |
Moq is a mocking library for .NET designed and developed to utilize .NET 3.5 features, e.g., Linq expression trees and lambda expressions. Moq's goal is to be simple and straightforward, allowing a natural integration into existing unit tests, instead of forcing developers to rewrite tests or learn extensive Record/Replay mocking frameworks. Moq targets those developers who are writing tests but are not using mocking frameworks. The design principle behind Moq is to be refactoring friendly with a very low barrier of entry.

Moq offers the following features:
  • Strong-typed: no strings for expectations, no object-typed return values or constraints
  • Unsurpassed VS intellisense integration: everything supports full VS intellisense, from setting expectations, to specifying method call arguments, return values, etc.
  • No Record/Reply idioms to learn. Just construct your mock, set your expectations, use it and optionally verify them
  • VERY low learning curve as a consequence of the previous three points. For the most part, you don't even need to ever read the documentation.
  • Granular control over mock behavior with a simple MockBehavior enumeration (no need to learn what's the theoretical difference between a mock, a stub, a fake, a dynamic mock, etc.)
  • Mock both interfaces and classes
  • Override expectations: can set default expectations in a fixture setup, and override as needed on tests
  • Pass constructor arguments for mocked classes
  • Intercept and raise events on mocks
  • Moq is open source and eager for more contributors. Along with the source, the binaries and a getting started guide are hosted on Google Code.

    Daniel Cazzulino, Moq's active maintainer, has a series of posts that provide his reasoning for creating Moq and several good examples of how to use Moq effectively.

    Hello stranger!

    You need to Register an InfoQ account or to post comments. But there's so much more behind being registered.

    Get the most out of the InfoQ experience.

    Tell us what you think

    Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

    Email me replies to any of my messages in this thread
    Community comments

    Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

    Email me replies to any of my messages in this thread

    Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

    Email me replies to any of my messages in this thread

    Discuss

    Educational Content

    General Feedback
    Bugs
    Advertising
    Editorial
    InfoQ.com and all content copyright © 2006-2013 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
    Privacy policy
    BT