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.

Setup

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.

Thoughts

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 😉

References

About erictummers

My work as a recruited developer changes almost every month. 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s