What's new? | Help | Directory | Sign in
Google
moq
The simplest mocking library for .NET 3.5 with deep C# 3.0 integration
  
  
  
  
    
License: New BSD License
Labels: .NET, C, Linq, Mock, TDD, 3.5, Lambda
var mock = new Mock<ILoveThisFramework>();

// WOW! No record/reply weirdness?! :)
mock.Expect(framework => framework.ShouldDownload(It.IsAny<Version>()))
    .Callback((Version version) => 
        Console.WriteLine("Someone wanted version {0}!!!", version))
    .Returns(true)
    .AtMostOnce();

// Hand mock.Object as a collaborator and exercise it, 
// like calling methods on it...
ILoveThisFramework lovable = mock.Object;
bool download = lovable.ShouldDownload(new Version("2.0.0.0"));

mock.VerifyAll();

What?

MoQ (pronounced "Mock-you" or just "Mock") is the only mocking library for .NET developed from scratch to take full advantage of .NET 3.5 (i.e. Linq expression trees) and C# 3.0 features (i.e. lambda expressions) that make it the most productive, type-safe and refactoring-friendly mocking library available. And it supports mocking interfaces as well as classes. Its API is extremely simple and straightforward, and doesn't require any prior knowledge or experience with mocking concepts.

Why?

The library was created mainly for developers who aren't currently using any mocking library (or are displeased with the complexities of some other implementation), and who are typically manually writing their own mocks (with more or less "fanciness"). Most developers in this situation also happen to be quite pragmatic and adhere to state (or classic) TDD. It's the result of feeling that the barrier of entry from other mocking libraries is a bit high, and a simpler, more lightweight and elegant approach is possible. MoQ achieves all this by taking full advantage of the elegant and compact C# 3.0 language features collectively known as LINQ (they are not just for queries, as the acronym implies).

MoQ is designed to be a very practical, unobtrusive and straight-forward way to quickly setup dependencies for your tests. Its API design helps even novice users to fall in the "pit of success" and avoid most common misuses/abuses of mocking.

Currently, it's the only mocking library that goes against the generalized and somewhat unintuitive (especially for novices) Record/Reply approach from all other frameworks (and this might be a good thing ;)).

Not using Record/Reply also means that it's straightforward to move common expectations to a fixture setup method and even override those expectations when needed in a specific unit test.

You can read more about the "why" and see some nice screenshots at kzu's blog.

Where?

See our QuickStart examples to get a feeling of the extremely simple API and download the latest binaries, source code and help file.

Read about the announcement at kzu's blog. Get some background on the state of mock libraries from Scott Hanselman.

Browse the API documentation to get a feeling of how extremely simple it is to use.

Who?

MoQ was jointly developed by Clarius, Manas and InSTEDD. You can read more about it at InSTEDD MoQ page.

Features at a glance

MoQ offers the following features:

Check the ChangeLog to learn about features introduced with each version.

Want to join and contribute?

Checkout our HowToContribute page!