NSubstitute 6.0.0-rc.1
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
- For C# projects: NSubstitute.Analyzers.CSharp
- For VB projects: NSubstitute.Analyzers.VisualBasic
Getting help
If you have questions, feature requests or feedback on NSubstitute please raise an issue on our project site.
More information
- Visit NSubstitute website for more examples and documentation.
- Visit NSubstitute on GitHub.
No packages depend on NSubstitute.
.NET 8.0
- Castle.Core (>= 5.1.1)
.NET Standard 2.0
- Castle.Core (>= 5.1.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
| Version | Downloads | Last updated |
|---|---|---|
| 6.0.0-rc.1 | 4 | 03/21/2026 |
| 5.3.0 | 6 | 12/20/2025 |
| 5.1.0 | 6 | 12/28/2025 |
| 5.0.0 | 8 | 12/13/2025 |
| 4.4.0 | 7 | 12/20/2025 |
| 4.3.0 | 8 | 12/13/2025 |
| 4.2.2 | 6 | 12/18/2025 |
| 4.2.1 | 6 | 01/18/2026 |
| 4.2.0 | 6 | 01/18/2026 |
| 4.1.0 | 9 | 12/13/2025 |
| 4.0.0 | 8 | 01/07/2026 |
| 3.1.0 | 6 | 12/17/2025 |
| 3.0.1 | 6 | 12/16/2025 |
| 2.0.3 | 8 | 01/13/2026 |
| 1.10.0 | 9 | 01/18/2026 |
| 1.9.2 | 8 | 12/18/2025 |
| 1.9.1 | 7 | 12/13/2025 |
| 1.8.2 | 9 | 12/13/2025 |
| 1.8.1 | 10 | 01/15/2026 |
| 1.8.0 | 8 | 12/13/2025 |
| 1.7.2 | 7 | 01/19/2026 |
| 1.7.1 | 8 | 12/13/2025 |
| 1.7.0 | 9 | 12/13/2025 |
| 1.6.1 | 10 | 12/13/2025 |
| 1.6.0 | 8 | 12/13/2025 |
| 1.5.0 | 8 | 12/13/2025 |
| 1.4.3 | 9 | 12/13/2025 |
| 1.4.2 | 8 | 12/13/2025 |
| 1.4.1 | 8 | 12/13/2025 |
| 1.4.0 | 9 | 01/14/2026 |
| 1.3.0 | 9 | 12/23/2025 |
| 1.2.1 | 9 | 01/12/2026 |
| 1.2.0 | 9 | 01/17/2026 |
| 1.1.0 | 8 | 12/13/2025 |
| 1.0.0 | 9 | 12/16/2025 |