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.
Latest public signals
Not refreshed yet. Refresh reads the public site and, when the entry has a GitHub repository, the latest release.
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
- Lambda-based setups: Strongly typed
SetupandVerify. - Argument matchers:
It.IsAny,It.Isand more. - Async support:
ReturnsAsyncandThrowsAsync. - Mock.Of: Declarative mocks with LINQ expressions.
Pros
- Free to use: Open source under the MIT licence, so the core tool costs nothing to use.
- Actively maintained: The repository had commits as recent as 10 November 2026.
- Community: About 6,400 GitHub stars.
Cons
- Interfaces and virtual members only: Cannot mock sealed classes or non-virtual members.
- Version transition: Documentation differs between stable v4 and upcoming v5.
Usage and Links (Example)
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.
Recommended for?
- .NET teams needing a widely documented mocking library.
- 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.
NNSubstituteNSubstitute is a BSD-3-Clause mocking library for .NET with a concise, readable syntax for creating substitutes, configuring returns and checking received calls.Compare with Moq
XxUnit.netxUnit.net is a free, Apache-2.0, community-focused unit testing tool for C#, F# and Visual Basic, part of the .NET Foundation; v3 supports .NET 8+ and .NET Framework 4.7.2+.Compare with Moq
NNUnitNUnit is an MIT-licensed unit-testing framework for all .NET languages on Windows, macOS and Linux, broad and non-opinionated, now at version 5 after NUnit 3 and 4.Compare with Moq
MMSTestMSTest is Microsoft's MIT-licensed test framework for .NET, developed in the microsoft/testfx repository alongside Microsoft.Testing.Platform, a lightweight alternative to VSTest, with the MSTest.Sdk project SDK.Compare with Moq
FFluent AssertionsFluent Assertions is a .NET assertions library with natural-language `Should()` syntax; versions 8 and later are free for open-source and non-commercial use but require a paid licence (via Xceed) for commercial use.Compare with Moq
MMockitoMockito is the MIT-licensed, most popular mocking framework for Java, used to create mocks, stubs and spies with a clean API; Mockito 5 uses the inline mock maker by default and requires Java 11.Compare with Moq