BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Moq .NET Mocking Library

Moq .NET Mocking Library

This item in japanese

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.

    Rate this Article

    Adoption
    Style

    BT