CheckOps home

Tools directory

M

CheckOps

Moq

Moq is a popular MIT-licensed mocking library for .NET that uses lambda expressions to set up and verify mocks; stable v4.x is maintained on the v4 branch while the main branch hosts the upcoming v5.

Visit website

Latest public signals

Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.

Visit Website

Introduction

Moq describes itself as the most popular and friendly mocking framework for .NET. In the widely used v4 series, you create a Mock<T> for an interface or virtual class, configure behaviour with Setup(x => x.Method(...)).Returns(...), pass mock.Object to the code under test, and check interactions with Verify(...). Argument matchers such as It.IsAny<T>() and It.Is<T>(predicate) make setups flexible, and Mock.Of<T>() creates mocks declaratively with LINQ-style expressions.

The repository’s main branch now contains the upcoming Moq v5, while the source and licence for the current stable v4.x live on the v4 branch, according to the README. v5 introduces typed setups generated for each mocked member (C# 14+), a Verify.Called(...) API, and compiles Mock<T> into your test project as source so mock creation can be customised with partial classes. Teams should check which version they are using when reading documentation. Moq supports async methods (ReturnsAsync), callbacks, sequences, strict and loose behaviour and events. The latest GitHub release, v4.21.0, was published on 24 September 2026.

The source code is at devlooped/moq on GitHub under the MIT licence, with about 6,400 stars; the most recent commit was on 10 November 2026.

Features

  1. Lambda-based setups: Strongly typed Setup and Verify.
  2. Argument matchers: It.IsAny, It.Is and more.
  3. Async support: ReturnsAsync and ThrowsAsync.
  4. Mock.Of: Declarative mocks with LINQ expressions.

Pros

  1. Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
  2. Actively maintained: The repository had commits as recent as 10 November 2026.
  3. Community: About 6,400 GitHub stars.

Cons

  1. Interfaces and virtual members only: Cannot mock sealed classes or non-virtual members.
  2. Version transition: Documentation differs between stable v4 and upcoming v5.
var repo = new Mock<IOrderRepository>();
repo.Setup(r => r.GetAsync(42)).ReturnsAsync(new Order { Id = 42, Total = 100 });

var service = new InvoiceService(repo.Object);
var invoice = await service.CreateAsync(42);

Assert.Equal(100, invoice.Amount);
repo.Verify(r => r.SaveAsync(It.Is<Order>(o => o.Invoiced)), Times.Once);

Resources:

Pricing

Moq is free and open source under the MIT licence.

  1. .NET teams needing a widely documented mocking library.
  2. Codebases built around interfaces and dependency injection.

Conclusion

Moq remains one of the most widely used .NET mocking libraries, with a stable v4 line and a significantly redesigned v5 in development.

Alternatives

Other tools on CheckOps that cover similar ground. Open a page, or compare one with Moq side by side.