xUnit.net

{{Short description|Software testing framework for .NET software framework}}

{{about|the xUnit.net software|all unit-testing frameworks like '_Unit'|xUnit}}

{{lowercase title}}

{{Infobox software

| name = xUnit.net

| logo = XUnit.net Logo.png

| logo size = 200px

| screenshot = XUnit.net GUI.png

| screenshot size = 300px

| caption = xUnit.net 1.9.1 GUI on Windows

| author = James Newkirk, Brad Wilson

| developer = Microsoft, Outercurve Foundation, .NET Foundation

| latest release version = 2.6.2{{Cite web|url=https://github.com/xunit/xunit/releases|title=Releases · xunit/xunit|website=GitHub}}

| latest release date = {{Start date and age|2023|11|18}}

| repo = {{URL|https://github.com/xunit/xunit/}}

| programming language = C#

| operating system = Windows, macOS, Linux

| platform = .NET Framework, .NET Core, Mono

| genre = Unit testing tool

| license = Apache License 2.0

| website = {{URL|https://xunit.net/}}

}}

xUnit.net is a free and open-source unit testing tool for the .NET Framework, written by the original author of NUnit. The software can also be used with .NET Core and {{Cite web|url=https://www.infoq.com/articles/testing-aspnet-core-web-api/|title=How to Test ASP.NET Core Web API|website=InfoQ}} Mono.

It is licensed under Apache License 2.0, and the source code is available on GitHub.{{Cite web|url=https://github.com/xunit/xunit/blob/main/LICENSE|title=About xUnit.net|website=GitHub|date=4 November 2021}} xUnit.net works with Xamarin, ReSharper, CodeRush, and TestDriven.NET.{{Cite web|url=https://www.infoworld.com/article/3168787/how-to-work-with-xunit-net-framework.html|title=How to work with xUnit.Net framework|first=Joydip|last=Kanjilal|date=February 10, 2017|website=InfoWorld}} It is authored by James Newkirk and Brad Wilson.{{Cite web|url=https://bradwilson.typepad.com/blog/2012/09/leaving-microsoft.html|title=Leaving Microsoft|website=Brad Wilson}}

Example

Example of an xUnit.net test fixture:

using Xunit;

public class MyTests

{

[Fact]

public void MyTest()

{

Assert.Equal(4, 2 + 2);

}

}

After you compile the test, run it in your console:

C:\MyTests\bin\Debug>xunit.console MyTestLibrary.dll

xUnit.net console test runner (64-bit .NET 2.0.50727.0)

Copyright (C) 2007-11 Microsoft Corporation.

xunit.dll: Version 1.9.1.0

Test assembly: C:\MyTests\bin\Debug\MyTestLibrary.dll

1 total, 0 failed, 0 skipped, took 0.302 seconds

See also

{{Portal|Free and open-source software}}

References

{{Reflist}}

Further reading

  • {{cite book|last=Ayobami|first=Adewole|year=2018|title=C# and .NET Core Test-Driven Development: Dive into TDD to create flexible, maintainable, and production-ready .NET Core applications|publisher=Packt Publishing|isbn=978-1788299923}}
  • {{cite book|last=Nagel|first=Christian|year=2021|title=Professional C# and .NET|publisher=John Wiley & Sons|isbn=978-1119797210}}