Live Unit Testing with xUnit in VS2019

This is a reminder to myself more than anything else.
It is not often that I get to greenfield a new project. Most of the time, the solution already exists, and I start hacking away at it in my normal enthusiastic fashion.

I am a big fan of xUnit as a unit-testing framework.
Not that it has any particular advantages imho, but rather, at the time I was nosing into various test frameworks, xUnit was the only one that supported everything you threw at it; Xamarin projects, .Net Core projects etc. So I picked up its syntax, and stuck with it as my preference to day’s date.

Whenever I start a new solution in Visual Studio, I typically include references to a handful of the xUnit nuget packages in my unit-testing projects:

xunit
xunit.core
xunit.runner.visualstudio
xunit.assert
xunit.runner.console

I am also a huge fan of the feature “Live Unit testing” in Visual Studio. The responsiveness of writing unit-tests and immediately see them fail/pass as you hit save is just so powerful! Once you try it, you’ll never go back. Honest!

Anyways, if you do this, and run the code, you’ll get an error once you activate live unit testing in Visual Studio. The error message comes from XUnit which claims (among other things) the following:

Exception filtering tests: No tests matched the filter because it contains one or more properties that are not valid (TestCategory, Category)

And then of course, you resort to GDD (Google-Driven Development), upon which you’ll find dozens of articles with workarounds for this issue, most of them recommend creating a dummy unit-test class with the necessary categories added to them.

BUT, there is another solution that works fine with .Net Framework versions as well as .Net Core (tested upto version 3.0):

Simply add the following package from nuget:

Microsoft.Net.Test.SDK

Once this package is added to the solution, the Live Unit Testing immediately starts working, and life becomes good again.


As I mentioned, this is a reminder to myself, mostly, but I figured I’d post it here, in case more of you struggle with the same issue 🙂

Happy Unit-Testing!

USEFUL LINKS
Download Visual Studio here: visualstudio.com
XUnit Homepage: xunit.net
Nuget Package Manager: nuget.org

About digitaldias

Software Engineer during the day, photographer, videographer and gamer in the evening. Also a father of 3. Pedro has a strong passion for technology, and gladly shares his findings with enthusiasm.

View all posts by digitaldias →

2 Comments on “Live Unit Testing with xUnit in VS2019”

Leave a Reply

Your email address will not be published. Required fields are marked *

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