Skip to main content
net8.0.NETStandard2.0

NSubstitute is a friendly substitute for .NET mocking libraries. It has a simple, succinct syntax to help developers write clearer tests. NSubstitute is designed for Arrange-Act-Assert (AAA) testing and with Test Driven Development (TDD) in mind.

Published
Mar 15, 2026
7mo ago
Total Downloads
312.5M
312,496,183

Install

dotnet add package NSubstitute --version 6.0.0-rc.1
ProductVersions
.NET
net8.0
.NET Standard
netstandard2.0

README

NSubstitute

A friendly substitute for .NET mocking libraries.

Perfect for those new to testing, and for others who would just like to to get their tests written with less noise and fewer lambdas.

How to use

// Create:
var calculator = Substitute.For<ICalculator>();

// Set a return value:
calculator.Add(1, 2).Returns(3);
Assert.AreEqual(3, calculator.Add(1, 2));

// Check received calls:
calculator.Received().Add(1, Arg.Any<int>());
calculator.DidNotReceive().Add(2, 2);

// Raise events
calculator.PoweringUp += Raise.Event();

Optional Roslyn analysers

Getting help

If you have questions, feature requests or feedback on NSubstitute please raise an issue on our project site.

More information

Changes from Previous Version

v5.3.0v6.0.0-rc.1
Added Frameworks
net8.0
Removed Frameworks
.NETFramework4.6.2net6.0
Added Dependencies
Castle.Core(net8.0)
Removed Dependencies
Castle.Core(.NETFramework4.6.2)
Castle.Core(net6.0)

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 2 target frameworks; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.