About xUnit.net
xUnit.net is a free, open source, community-focused unit testing tool for C#, F#, and Visual Basic. xUnit.net v3 support .NET 8.0 or later, and .NET Framework 4.7.2 or later.
xUnit.net works with the .NET SDK command line tools, Visual Studio, Visual Studio Code, JetBrains Rider, NCrunch, and any development environment compatible with Microsoft Testing Platform or VSTest.
xUnit.net is part of the .NET Foundation and operates under their code of conduct. It is licensed under Apache 2 (an OSI approved license). The project is governed by a Project Lead.
Follow: xUnit.net on Mastodon, xUnit.net on Bluesky, Brad Wilson, James Newkirk
JetBrains Rider support is provided and supported by JetBrains.
NCrunch support is provided and supported by Remco Software.
The xUnit.net logo was designed by Nathan Young.
Quick Start with .NET SDK
Install the xUnit.net v3 project templates:
dotnet new install xunit.v3.templates
The following template packages will be installed:
xunit.v3.templates
Success: xunit.v3.templates::2.0.3 installed the following templates:
Template Name Short Name Language Tags
------------------------------ ---------------- ---------- ----------
xUnit.net v3 Extension Project xunit3-extension [C#],F#,VB Test/xUnit
xUnit.net v3 Test Project xunit3 [C#],F#,VB Test/xUnit
Create a unit test project:
dotnet new xunit3 --language C#
The template "xUnit.net v3 Test Project" was created successfully.
Processing post-creation actions...
Restoring C:\Dev\SampleProject\SampleProject.csproj:
Restore succeeded.
Edit UnitTest1.cs
:
namespace SampleProject;
public class UnitTest1
{
public static int Add(int x, int y) =>
x + y;
[Fact]
public void Good() =>
Assert.Equal(4, Add(2, 2));
[Fact]
public void Bad() =>
Assert.Equal(5, Add(2, 2));
}
Execute the tests:
dotnet run
xUnit.net v3 In-Process Runner v2.0.3+216a74a292 (64-bit .NET 8.0.17)
Discovering: SampleProject
Discovered: SampleProject
Starting: SampleProject
SampleProject.UnitTest1.Bad [FAIL]
Assert.Equal() Failure: Values differ
Expected: 5
Actual: 4
Stack Trace:
UnitTest1.cs(14,0): at SampleProject.UnitTest1.Bad()
Finished: SampleProject
=== TEST EXECUTION SUMMARY ===
SampleProject Total: 2, Errors: 0, Failed: 1, Skipped: 0, Not Run: 0, Time: 0.054s
Latest Release Notes
Stable | Prerelease | |
---|---|---|
Core Framework v3 | 3.0.0 | None |
Core Framework v2 | 2.9.3 | None |
Analyzers | 1.23.0 | None |
Visual Studio adapter | 3.1.2 | None |
For older release notes, see the full release notes list.
Latest NuGet Packages
Latest stable | Latest CI (how to use) | Build status | |
---|---|---|---|
xunit.v3 |
|||
xunit |
|||
xunit.analyzers |
|||
xunit.runner.visualstudio |
Issues and Discussions
- Issues in the core framework and analyzers should be reported in the primary issue tracker
- Issues in
xunit.runner.visualstudio
should be reported in the project issue tracker - Discussions are hosted in the primary discussion forums
Github Projects
- xUnit.net (core framework, built-in runners)
- Assertion library
- Analyzers
- Visual Studio adapter
- Media files
- This site
Links to Resources
Sponsors
Help support this project by becoming a sponsor through GitHub Sponsors.
Additional copyrights
Portions copyright The Legion Of The Bouncy Castle