NUnit documentation
Write tests you can trust, for any .NET code
NUnit is the open-source unit-testing framework for .NET. Write a test in a few lines, get warnings about mistakes as you type from the NUnit Analyzers, run it with many sets of data, and run it anywhere: in Visual Studio, Rider, VS Code, on the command line or in your build pipeline.
Popular: Test with many inputs Checking results Preparing and cleaning up Tests that depend on each other Flaky tests Running tests in parallel Microsoft.Testing.Platform Upgrading to NUnit 5 Analyzer warnings
using NUnit.Framework;
public class CalculatorTests
{
[TestCase(2, 3, 5)]
[TestCase(-1, 1, 0)]
public void Add_ReturnsSum(int a, int b, int expected)
{
var result = new Calculator().Add(a, b);
Assert.That(result, Is.EqualTo(expected));
}
}
Writing tests
From a single test to tests that run with hundreds of inputs.
- Ordinary tests
- Preparing and cleaning up
- Data driven tests
- Automating tests
- Checking several things at once
- Tests that depend on other tests
- Flaky and slow tests
- Organizing and selecting tests
Reference
Getting started
Create a test project in the tool you already use, or add NUnit to an existing one.
News
Release notes for NUnit and all its tools.
Run anywhere
Run your tests in the IDE, on the command line or in your build.
NUnit Tech
How NUnit and its tools work under the hood.
Articles
Practical guides and deeper reading.
Developer info
For contributors to the NUnit projects.
Advanced
Make NUnit do more than it does out of the box.
Archive
Documentation for older versions and for tools that are no longer maintained.
Questions? Ask in GitHub Discussions · NUnit on GitHub · Help improve these docs · License