How to Fix Visual Studio Not Running xUnit Tests

visual studio Feb 17, 2021

Solution (TLDR)

Make sure the xunit.runner.visualstudio NuGet package is installed in your unit test project.

Problem

My task was to update an old codebase to switch an outdated validation mechanism to the newer method. Fairly straightforward - I only needed two lines of code.

Happy that I'd be able to quickly mark this task as done, I tried to run the solution. Test that everything still worked.

However, that didn't go as smoothly as I expected.

I ran into a dreaded assembly binding issue (will post about it when I resolve that issue!)

Frustrated, I turned to the unit test project included with the codebase. Hopefully it will work, I thought. My frustration just grew when I clicked "Run all tests" and nothing happened.

Visual Studio ignoring my tests :(

Solution

The problem was there was no error message or anything that could help me figure out why Visual Studio wouldn't run the unit tests. It would just fail silently.

After some digging, I remembered that xUnit (the framework used by the unit test project) needed a separate NuGet package to be able to run tests in Visual Studio.

How to Install the xUnit Visual Studio Runner

  1. Right-click the unit test project > Manage NuGet Packages
  2. In the Browse tab, search for "xunit"
  3. Install the xunit.runner.visualstudio NuGet package to your project.
The NuGet package screen with the xUnit Visual Studio runner package selected

And that's all it took - Visual Studio found the tests and ran them all. (As for the test results - there were no failed tests, yay!)

Hope this helps someone scratching their head why Visual Studio keeps ignoring their unit tests!

Photo by Girl with red hat on Unsplash

Kristina Alberto

Software engineer from Sydney. I work at Domain Group.