Why is the Visual Studio 2015/2017/2019 Test Runne

2020-01-24 19:06发布

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.

30条回答
家丑人穷心不美
2楼-- · 2020-01-24 19:49

It's happened to me a couple of times - when I Clean the project and Build it again it tends to be fine.

查看更多
Juvenile、少年°
3楼-- · 2020-01-24 19:49

My problem was resolved by installing the nuget xunit.runner.visualstudio

查看更多
Rolldiameter
4楼-- · 2020-01-24 19:50

Follow this steps :

  1. Update your MsTest.TestAdapter and MsTest.TestFramework dll's from nugget package manager.
  2. Clean your solution
  3. Build your solution.
查看更多
ゆ 、 Hurt°
5楼-- · 2020-01-24 19:50

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 :).

查看更多
迷人小祖宗
6楼-- · 2020-01-24 19:51

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?

  • Open the Output window.
  • Change drop-down selection for Show output from to Tests.
  • 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:

    Exception System.OutOfMemoryException, Exception converting <SignatureOfYourTestMethod>
    Array dimensions exceeded supported range.
    

If yes, do this to resolve the problem:

  • Open your test project's Properties (select the test project in Solution Explorer and press Alt+Enter).
  • Switch to the Build tab.
  • Click on the Advanced... button (located at the very end of that tab page).
  • In the drop-down labelled Debugging information, choose none, pdb-only, or full, but NOT portable. It is this last setting that causes the tests to not be found.
  • Click OK and clean & rebuild your project. If you want to be extra sure, go to your test project's output directory and clean all .pdb files before rebuilding. Now your tests should be back.
查看更多
来,给爷笑一个
7楼-- · 2020-01-24 19:54
  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. 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

  3. 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


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)

查看更多
登录 后发表回答