Why is the Visual Studio 2015/2017/2019 Test Runner not discovering my xUnit v2 tests

UPDATE: Adding a 2019; the discovery/runner integration mechanism is same as per 2017 & 2015, so the key things that can go wrong are the same.


I’ve read Why is the xUnit runner not finding my tests, which covers reasons xUnit would never be able to find your tests but my problem is different – I’m confident there’s nothing subtle going on with my tests; (they have worked in other environments, this seems to be just my machine) – the Visual Studio Test Runner in Visual Studio 2015 [Community Edition] is simply not showing any of my tests. I’m not doing anything remotely exciting; the tests target xUnit.net v2 on the Desktop.

I’ve looked in the Output window and am not seeing anything in at all under Test in the Show output from tabs.

40 Answers
40

  1. Eliminate discovery exceptions from your inquiries; go to the output Window (Ctrl-Alt-O), then switch the show output from dropdown (Shift-Alt-S) to Tests and make sure there are no discovery exceptions

  2. Test|Test settings|Default processor architecture can help if your tests are x86/x64 specific and discovery is triggering bittedness-related exceptions, i.e. not AnyCpu

  3. As suggested in this answer(upvote it if the technique helps)
    running the desktop console runner (instructions) can be a good cross check to eliminate other possibilities, e.g. mangled config files:-

    packages\xunit.runner.console.2.2.0\tools\xunit.console <tests.dll>

    NOTE The xunit.runner.console package is deprecated – when you get stuff working in VS, you’ll be able to have dotnet test run them in CI contexts too


Go read the documentation – it’s comprehensive, up to date, includes troubleshooting info and takes PRs:-

Important note: If you’ve previously installed the xUnit.net Visual Studio Runner VSIX (Extension), you must uninstall it first. The Visual Studio runner is only distributed via NuGet now. To remove it, to go Tools > Extensions and Updates. Scroll to the bottom of the list, and if xUnit.net is installed, uninstall it. This will force you to restart Visual Studio.

If you’re having problems discovering or running tests, you may be a victim of a corrupted runner cache inside Visual Studio. To clear this cache, shut down all instances of Visual Studio, then delete the folder %TEMP%\VisualStudioTestExplorerExtensions. Also make sure your project is only linked against a single version of the Visual Studio runner NuGet package (xunit.runner.visualstudio).

The following steps worked for me:

  1. (Only if you suspect there is a serious mess on your machine – in general the more common case is that the visual studio integration is simply not installed yet)

    Do the DEL %TEMP%\VisualStudioTestExplorerExtensions as advised :-

    PS> del $env:TEMP\VisualStudioTestExplorerExtensions

  2. Install the NuGet Package xunit.runner.visualstudio in all test projects

    • Paket:

      .paket\paket add nuget xunit.runner.visualstudio -i
      

      You need to end up with the following in your paket.dependencies:

      nuget xunit.runner.visualstudio version_in_path: true

      Note the version_in_path: true bit is important

    • Nuget: Go to Package Manager Console (Alt-T,N,O) and

      Install-Package xunit.runner.visualstudio)
      

    Rebuild to make sure xunit.runner ends up in the output dir

  3. Close Test Explorer <- this was the missing bit for me

  4. Re-open Test Explorer (Alt-S,W,T)

  5. Run All tests (Ctrl R, A)

Leave a Comment