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.
It's happened to me a couple of times - when I Clean the project and Build it again it tends to be fine.
My problem was resolved by installing the nuget xunit.runner.visualstudio
Follow this steps :
MsTest.TestAdapter
andMsTest.TestFramework
dll's
fromnugget package manager
.In my case, I had 2 different test projects in the solution. Project 1 tests could be found, but Project 2 tests could not. I found that first Unloading the test Project 1, then closing VS > clearing my temp files > re-open solution > rebuild, allowed VS to discover my Project 2 tests.
I'm assuming something must be conflicting between the two test projects and this was the quickest way to get me up and running in a few minutes. The kinks can be worked out later :).
There is one other reason that can cause Test Explorer not showing any tests, and it has to do with the new portable
.pdb
file format introduced with Visual Studio 2017 / for .NET Core which can break some VS tooling. (Background: See the bug report "Mono.Cecil causes OutOfMemoryException with new .csproj PDBs".)Are your tests not found because of the new portable
.pdb
(debug symbols) format?If you see output like to the following (possibly repeated once for each of your tests), then you've got the problem described in this answer:
If yes, do this to resolve the problem:
none
,pdb-only
, orfull
, but NOTportable
. It is this last setting that causes the tests to not be found..pdb
files before rebuilding. Now your tests should be back.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
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:-
NOTE The
xunit.runner.console
package is deprecated - when you get stuff working in VS, you'll be able to havedotnet test
run them in CI contexts tooTest|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
Go read the documentation - it's comprehensive, up to date, includes troubleshooting info and takes PRs:-
The following steps worked for me:
(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
Install the NuGet Package
xunit.runner.visualstudio
in all test projectsPaket:
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 importantNuget: Go to Package Manager Console (Alt-T,N,O) and
Rebuild to make sure
xunit.runner
ends up in the output dirClose Test Explorer <- this was the missing bit for me
Re-open Test Explorer (Alt-S,W,T)
Run All tests (Ctrl R, A)