site/index.md
{.dnflogo}
xUnit.net is a free, open source, community-focused unit testing tool for C#, F#, and Visual Basic. xUnit.net v3 supports .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.
{ .about-links }
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.
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
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 F#
The template "xUnit.net v3 Test Project" was created successfully.
Processing post-creation actions...
Restoring C:\Dev\SampleProject\SampleProject.fsproj:
Restore succeeded.
Edit UnitTest1.fs:
module UnitTest1
open Xunit
let Add(x: int, y: int) =
x + y
[<Fact>]
let Good() =
Assert.Equal(4, Add(2, 2))
[<Fact>]
let Bad() =
Assert.Equal(5, Add(2, 2))
Execute the tests: dotnet run
dotnet run
xUnit.net v3 In-Process Runner v2.0.3+216a74a292 (64-bit .NET 8.0.17)
Discovering: SampleProject
Discovered: SampleProject
Starting: SampleProject
UnitTest1.Bad [FAIL]
Assert.Equal() Failure: Values differ
Expected: 5
Actual: 4
Stack Trace:
UnitTest1.fs(14,0): at UnitTest1.Bad()
Finished: SampleProject
=== TEST EXECUTION SUMMARY ===
SampleProject Total: 2, Errors: 0, Failed: 1, Skipped: 0, Not Run: 0, Time: 0.052s
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 VB
The template "xUnit.net v3 Test Project" was created successfully.
Processing post-creation actions...
Restoring C:\Dev\SampleProject\SampleProject.vbproj:
Restore succeeded.
Edit UnitTest1.vb:
Imports Xunit
Public Class UnitTest1
Public Function Add(x As Integer, y As Integer) As Integer
Return x + y
End Function
<Fact>
Public Sub Good()
Assert.Equal(4, Add(2, 2))
End Sub
<Fact>
Public Sub Bad()
Assert.Equal(5, Add(2, 2))
End Sub
End Class
Execute the tests: dotnet run
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.vb(16,0): at SampleProject.UnitTest1.Bad()
Finished: SampleProject
=== TEST EXECUTION SUMMARY ===
SampleProject Total: 2, Errors: 0, Failed: 1, Skipped: 0, Not Run: 0, Time: 0.052s
{: .latest }
| Stable | Prerelease | |
|---|---|---|
| Core Framework v3 | 3.2.2{: .release } | None |
| Core Framework v2 | 2.9.3{: .release } | None |
| Analyzers | 1.27.0{: .release } | None |
| Visual Studio adapter | 3.1.5{: .release } | None |
For older release notes, see the full release notes list.
{: .table .latest }
| Latest stable | Latest CI (how to use) | Build status | |
|---|---|---|---|
xunit.v3 | |||
xunit | |||
xunit.analyzers | |||
xunit.runner.visualstudio |
xunit.runner.visualstudio should be reported in the project issue trackerHelp support this project by becoming a sponsor through GitHub Sponsors.
Portions copyright The Legion Of The Bouncy Castle