NUnit tests is not found or do not run in Visual Studio's Test Explorer
Having problems with your NUnit tests not running as expected in Visual Studio's Test Explorer? Even wiered, the tests might work for other members of your team but for some reason not for you?
(Spoiler alert: maybe the rest of your team is using ReSharper?)
The Problem:
A lot of the times when I am joining a new project and I clone the repo and try to run all the unit tests locally I face this issue:
-"Test run finished: 0 Tests (0 Passed, 0 Failed, 0 Skipped)"
The Visual Studio Test Explorer says that it can't find any tests, even though I can see that it found 306 tests? And when looking in the test output we see these wierd errors being logged:
-"No tests available in C:\.."
However if we scroll up a bit in the test output window we will get this clue to why this happends:
-"Test project does not reference any .NET NuGet adapter. Test discovery or execution might not work for this project. It's recommended to reference NuGet test adapters in each test project in the solution."
The solution:
Almost always when I face this issue, the problem is that the project does not have any Test Adapter or Runner installed, and so Visual Studio cannot run the tests in the Test Explorer.
The solution however is simple:
PM > Install-Package NUnit.ConsoleRunner
PM > Install-Package NUnit3TestAdapter
All done! ✅
Your tests should run fine from this point forward.
But..:
-"But these tests seems to be running for everyone else in my team."
Well, have you checked if they are using ReSharper? You see ReSharper comes packed with its own Runner and Adapter so the only thing you need is NUnit (or any other test framework) installed in your test project and the tests will be dicoverable and able to run in ReSharpers Test runner.
I don't use ReSharper myself and I refuse to install it just for the sake of running my tests. And the solution above won't break anything for the ReSharper users in your teams so there is no harm in installing this in your project to enable running tests for all the non-ReSharper devs.
Cheers friends! ❤️