Visual Studio 2015 or 2017 does not discover unit tests

test explorer not showing tests visual studio 2017
test explorer not showing tests visual studio 2019
visual studio test explorer not showing tests
visual studio test explorer unknown project
nunit tests not showing in test explorer visual studio 2017
visual studio 2017 debug unit test not working
visual studio test not being discovered
visual studio xunit tests not discovered

EDIT 2016-10-19:

The original question was about an issue specific to VS2015 CTP6 with the XUnit test runner. It's clear from the answers that there is a much broader issue with unit test discovery in Visual Studio which may occur in many different situations. I have cleaned up my question to reflect that.

I have also included a script in my own answer that I still use to this day to solve similar problems when they appear.

Many other answers have also proven helpful in better understanding the intricacies of the VS test runner. I appreciate that people are still sharing their solutions!


Original question 2015-04-10:

Since yesterday, my Visual Studio Test Explorer won't discover tests for any of my projects. It does not show the green loading bar after building, either.

When I go to the Visual Studio Test Explorer and click "Run All", or when I right-click any test method and select "Run Tests", I get the following in my output window:

Could not load file or assembly 'Microsoft.VisualStudio.Web.ProjectSystem, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I am running Visual Studio 2015 CTP 6 on Windows 10 Pro Technical Preview, build 10041. The .NET Framework version does not seem to matter - it happens on 4.0, 4.5.2 and 4.6.

I tried with the following testing frameworks and all of them give the same behavior:

  • Microsoft.VisualStudio.QualityTools.UnitTestFramework v14.0.22609.0
  • xunit v2.1.0-beta1-build2945 with xunit.runner.visualstudio v2.1.0-beta1-build1051
  • NUnit v2.6.4 with NUnitTestAdapter v2.0.0

I found an issue on GitHub (xunit) that appeared to be similar: Cannot get tests discovered #295, with this comment from the xunit team:

Be aware that Visual Studio 2015 CTP 5 has been reported to be broken by many people with unit testing in general (not just xUnit.net), so don't expect that to work.

Also, please make sure you've cleaned out Visual Studio's runner cache. If it gets corrupted, Visual Studio will permanently misbehave until it's deleted. To clear the cache, shut down all instances of Visual Studio, then delete the folder %TEMP%\VisualStudioTestExplorerExtensions (honestly, it probably wouldn't hurt to delete everything in %TEMP% that can be deleted).

I tried their suggestion to delete the folder %TEMP%\VisualStudioTestExplorerExtensions. Unfortunately that did not fix the problem.

I noticed that ReSharper actually is able to discover some tests. It only works for the VS and NUnit tests, not for xunit.

There has to be some sort of temp or cache folder I need to clear, but I know Visual Studio has many of them and not all of them can be deleted without unwanted side-effects.

Make sure your class with the [TestClass] attribute is public and not private.

Test Explorer not discoverying test methods, All unit test are standard, no third party libraries like mocking or nunit test etc. Using VS2017 Enterprise, C#, Framework 4.6.1, Windows 7. Be aware that Visual Studio 2015 CTP 5 has been reported to be broken by many people with unit testing in general (not just xUnit.net), so don't expect that to work. Also, please make sure you've cleaned out Visual Studio's runner cache.

I made the mistake of creating async methods but returning void.

Changed: public async void Test()

To: public async Task Test()

Why doesn't Visual Studio 2017 discover my unit tests?, An even bigger issue is that this is affecting Visual Studio 2015. When I go back to VS2015, I find my unit tests are no longer discoverable there  EDIT 2016-10-19: The original question was about an issue specific to VS2015 CTP6 with the XUnit test runner. It's clear from the answers that there is a much broader issue with unit test discover

Make sure your Test Methods do not have parameters. This is another way your test will not show up.

No Errors or Warnings.

Visual Studio 2017 doesn't discover all my unit tests, Visual Studio 2015 was able to discover all 824 unit tests. Then when I migrated my projects over to VS2017, it could not discover the tests. Be aware that Visual Studio 2015 CTP 5 has been reported to be broken by many people with unit testing in general (not just xUnit.net), so don’t expect that to work. Also, please make sure you’ve cleaned out Visual Studio’s runner cache. If it gets corrupted, Visual Studio will permanently misbehave until it’s deleted.

I would like to add one further reason tests may not be found, in my case it pertained C++ unit tests that were not found.

In my case tests were not found for a particular project because its output directory was not contained within the project directory, changing this ensured the tests were found.

Test Explorer FAQ, Test Explorer is not discovering my tests that are dynamically defined. In Visual Studio 2017 version 15.6 and later, assembly-based  Ever since I migrated over to Visual Studio 2017 from 2015, I've been having issues getting my unit tests to be discovered. I have a project with 824 unit tests. Visual Studio 2015 had no trouble discovering them.

If you are working with multiple App or Web.Config files. eg:

Its likely you are using a Config that is RELEASE MODE and that will strip the Debug mode setting from the config:

  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />

Change the Config to one that doesn't remove DEBUG MODE.

Test explorer does not discover tests in VS2015 Update 3 with vs14 , Test explorer does not discover tests in VS2015 Update 3 with vs14-kb3165756 #922 mismatch which allowed the test project to build ok but the unit tests would not load up. The fact that you're referencing xunit.runner.visualstudio is what suggests to me that .NET Core is only supported in VS 2017. Recently both stopped being able to discover MSTest unit tests, and Resharper also did not discover tests until I opened a file containing some tests. There was nothing in the Visual Studio log windows that indicated problems, and it proved to be an issue whose cause was hard to find. Unit test projects in VS2017 (not .NET Core) C# projects want to use the MSTest.TestAdapter and MSTest.TestFramework NuGet packages for the MSTest v2 libraries and integration.

How to fix unit test discovery in VS 2017 with MSTest V2? – Anthony , Microsoft Test Framework “MSTest V2” is the evolution of the Microsoft Test My unit tests were not discovered by Visual Studio 2017. How did  test explorer - keeps trying to discover tests and does nto complete windows 10.0 visual studio 2017 version 15.5 debugger testing-tools Greg Richmond reported Dec 11, 2017 at 12:34 AM

How to resolve cases of Visual Studio “No tests appearing”, The Visual Studio Test Explorer can be a bit picky about showing tests. This means your CI builds will work with unit tests “as is”. 1) Visual Studio 2017 introduces a new project system and thus a new project format. Visual Studio 2015 and NUnit, with a little NuGet issueNovember 14, 2014In "NuGet". In Visual Studio 2017 version 15.8 my tests are discovered, but don't execute. All test projects must include their .NET test adapter NuGet reference in their .csproj file. If they don't, the following test output appears on the project if discovery by a test adapter extension is kicked off after a build, or if the user tries to run the selected tests:

Visual studio 2017 debug unit test not working, Visual Studio 2015 was able to discover all 824 unit tests. It you want 7 vs2017 x64 unit test DO NOT WORK project testing-tools windows 10. There is no indicator in the TestExplorer that the execution of tests Aborted because of the bug. There seems to be a StackOverflowException that's unhandled or a bug in 15.5.3 Running the test via the VSTest command line also triggers the unit tests to abort. The active test run was aborted.

Comments
  • I'm so glad I stumbled upon this, it reminds me of why I'm using a 3rd party test runner (in my case ncrunch). I gave up on mstest a long time ago for similar reasons. Of course, that's no solution if you're stuck with mstest...
  • related: stackoverflow.com/questions/35103781/…
  • with VS 2017, incredibly enough, a cleaning of my temp and localappdata VS2017 related folders, a close + reload + clean solution and a Windows reboot didn't help. However, surprisingly, a simlpe "unload - reload" project on only one of my test projects did help the test discovery stopping hanging. I don't use 3rd party unit test package.
  • For some ppl this might be interesting or more relevant (I do not think I should add it as an answer) : No Source Available in Test Explorer - github.com/Microsoft/testfx/issues/274
  • This could be a fix for someone stackoverflow.com/a/58019304/1566372
  • This is most certainly not true since MSTest v2
  • Yes, there are already two answers on the front page from 3 years ago suggesting just that. One is the accepted answer, the other is the most-upvoted answer.
  • version 3.7 of what ?