Visual Studio 2015 或 2017 未发现单元测试 [英] Visual Studio 2015 or 2017 does not discover unit tests

查看:30
本文介绍了Visual Studio 2015 或 2017 未发现单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑 2016-10-19:

最初的问题是关于带有 XUnit 测试运行程序的 VS2015 CTP6 特有的问题.从答案中可以清楚地看出,Visual Studio 中的单元测试发现存在一个更广泛的问题,这可能在许多不同的情况下发生.我已经清理了我的问题以反映这一点.

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.

许多其他答案也被证明有助于更好地理解 VS 测试运行器的复杂性.我很感激人们仍在分享他们的解决方案!

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!

原始问题 2015-04-10:

从昨天开始,我的 Visual Studio 测试资源管理器不会发现我的任何项目的测试.构建后也不会显示绿色加载栏.

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.

当我转到 Visual Studio 测试资源管理器并单击全部运行"时,或者当我右键单击任何测试方法并选择运行测试"时,我会在输出窗口中看到以下内容:

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:

无法加载文件或程序集Microsoft.VisualStudio.Web.ProjectSystem, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"或其依赖项之一.系统找不到指定的文件.

我在 Windows 10 Pro Technical Preview 版本 10041 上运行 Visual Studio 2015 CTP 6..NET Framework 版本似乎无关紧要 - 它发生在 4.04.5.24.6.

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-build2945xunit.runner.visualstudio v2.1.0-beta1-build1051
  • NUnit v2.6.4NUnitTestAdapter v2.0.0
  • 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

我在 GitHub (xunit) 上发现了一个类似的问题:无法发现测试#295,来自 xunit 团队的评论:

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

请注意,已报告 Visual Studio 2015 CTP 5 已损坏由许多进行单元测试的人(不仅仅是 xUnit.net),所以不要指望这会奏效.

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.

另外,请确保您已经清除了 Visual Studio 的运行程序缓存.如果它被损坏,Visual Studio 将永久运行不正常直到被删除.要清除缓存,请关闭所有实例Visual Studio,然后删除文件夹%TEMP%\VisualStudioTestExplorerExtensions(老实说,它可能删除 %TEMP% 中可以删除的所有内容也无妨).

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

我尝试了他们的建议以删除文件夹 %TEMP%\VisualStudioTestExplorerExtensions.不幸的是,这并没有解决问题.

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

我注意到 ReSharper 实际上能够发现一些测试.它仅适用于 VS 和 NUnit 测试,不适用于 xunit.

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

必须有某种临时文件夹或缓存文件夹我需要清除,但我知道 Visual Studio 有很多文件夹,并非所有文件夹都可以删除而不会产生不必要的副作用.

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.

推荐答案

令我惊讶的是,清除位于 %TEMP% 目录中的临时文件为我解决了这个问题.

To my surprise, clearing temp files located in the %TEMP% directory resolved the issue for me.

注意:这个路径一般在C:\Users\(yourusername)\AppData\Local\Temp

作为@Warren-P,您可以通过在开始菜单中输入%temp% 导航到临时文件夹,或启动文件资源管理器"并输入%temp%在地址栏中.

As @Warren-P included, you can navigate to the temp folder by putting in %temp% in Start Menu, or launch "File Explorer" and enter %temp% in the address bar.

这篇关于Visual Studio 2015 或 2017 未发现单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆