NUnit & xUnit.net
The leading .NET unit testing frameworks. NUnit for classic style, xUnit.net for modern idiomatic .NET testing.
Overview
NUnit and xUnit.net are the two most popular unit testing frameworks for .NET. NUnit, inspired by JUnit, has been the standard for .NET testing since 2002. xUnit.net, created by the original NUnit developers in 2007, takes a more modern approach with cleaner architecture, better parallel execution, and fewer attributes.
Both frameworks integrate with Visual Studio, Rider, and all .NET CI/CD tools. Most NZ .NET teams use one or both. xUnit.net is the default choice for ASP.NET Core projects, while NUnit remains popular in legacy .NET Framework codebases.
What it's used for
NUnit/xUnit.net are essential for:
- .NET unit testing: The standard frameworks for testing C# and VB.NET code.
- ASP.NET Core testing: xUnit.net is the default for testing controllers, services, and middleware.
- Integration testing: Test database access, API clients, and external services.
- TDD workflows: Both frameworks support test-driven development with fast feedback.
Pros & Cons
Pros
- Native .NET integration — works seamlessly with Visual Studio and Rider
- Rich assertion libraries with fluent APIs
- Extensive parameterisation and data-driven test support
- Strong community and extensive documentation
- Integrate with all .NET CI/CD tools
Cons
- .NET only — not suitable for other languages
- NUnit can feel dated compared to xUnit.net
- xUnit.net has a steeper learning curve for NUnit migrants
- Some advanced features require additional packages
- Parallel test execution requires careful resource management
Platforms & Integrations
NUnit and xUnit.net run on Windows, macOS, and Linux via .NET Core/.NET 5+. They integrate with Visual Studio, Rider, VS Code, and all CI platforms.
Pricing
| Tier | Cost | Includes |
|---|---|---|
| Open Source | Free | Full framework, all features, community support |
NZ Context
NUnit and xUnit.net are standard in NZ .NET development teams. Government agencies, banks, and enterprise software companies in NZ heavily use .NET, making these frameworks essential skills. Inland Revenue and ACC use .NET extensively, and their test suites rely on NUnit or xUnit.net. For NZ testers working in .NET environments, familiarity with both is valuable.
Alternatives
- MSTest — Microsoft's built-in testing framework. Simpler but less flexible.
- Shouldly / FluentAssertions — Assertion libraries that pair with NUnit/xUnit for readable assertions.
- SpecFlow — BDD framework for .NET using Gherkin syntax.