Make sure the xunit.runner.visualstudio NuGet package is installed in your unit test project.
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.
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
- Right-click the unit test project > Manage NuGet Packages
- In the Browse tab, search for "xunit"
- Install the xunit.runner.visualstudio NuGet package to your project.
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