xUnit in Visual Studio

xUnitMy current project requires xunit for unit testing. I’m used to mstest as it is build into visual studio, but xunit integration is transparent with the extension installed.


To get xUnit working with the Test explorer install the xUnit.net runner extension. Also install the xUnit package from nuget for your project. Now you’re good to go.

Visual Studio has support for snippets. I added the factm snippet to expand to a method with the Fact attribute on it. Download my snippet from here.


I’m missing the Assert.Inconclusive method for reminding me about incomplete tests. Also I must stop clicking New Unittest and start creating New Class.

Where mstest uses an ExpectedException attribute, xunit uses Asserts.Throws. This makes the code more readable.
Xunit has Assert.Contains to check strings for containing a string. I was doing a check for true on string.Contains, the xunit method is shorter. Short is good 😉


About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Test and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.