To add xUnit to your project open up NuGet package manager

(Tools -> NuGet Package manager -> Manage Nuget packages for Solution


Right-click References of your project and chose Manage Nuget packages)

xUnit Nuget installation





And find xUnit package by  James Newkirk and Brad Wilson and press install.

To use xUnit in your project you do not have to decorate your class with TestClass attribute!

You must only decorate your methods with Fact Attribute.

Also be sure to reference Xunit assembly in your class file because xUnit’s Assert class is from that namespace.

If tests you write do not show in Test explorer, open NuGet  packet manager and add xunit.runner.visualstudio package (do not be confused if you see Visual Studio 2012+ in description, it is just saying that this is for version from VS 2012 an onwards).

There is also neat trick to modify name of your tests. By default Test explorer is showing xUnit’s test names in format Class.Method, but you can only display test Method names. Add new json file to root of project and name it “xunit.runner.json” and open properties of that file and under “Copy to Output Directory”  option chose “Copy if newer”.













Open under xunit.runner.json file and under Schema input “”, then inside brackets type “methodDisplay”: “method”.





Happy unit testing 🙂