更新:增加2019年;发现/运行器集成机制与2017年和2015年相同,因此可能出错的关键问题是相同的。


我读过为什么xUnit运行者找不到我的测试,其中包括xUnit永远无法找到你的测试的原因,但我的问题是不同的-我相信我的测试没有微妙的事情发生;(他们在其他环境中工作,这似乎只是我的机器)- Visual Studio 2015[社区版]中的Visual Studio测试运行器根本不显示我的任何测试。我没有做任何令人兴奋的事情;测试的目标是桌面上的xUnit.net v2。

我已经看了输出窗口,并没有看到任何东西在测试下从选项卡显示输出。


当前回答

遇到类似的问题,VS没有发现测试方法。在我的情况下,我有静态关键字的方法,我删除了它,它工作。

[TestMethod]

Before: public static void Test1()

After: public void Test1()

其他回答

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

注意:xunit.runner.console包已经弃用了——当你在VS中得到一些东西时,你也可以让dotnet测试在CI上下文中运行它们


去阅读文档-它是全面的,最新的,包括故障排除信息和PRs:-

重要提示:如果您之前已经安装了xUnit.net Visual Studio Runner VSIX(扩展),则必须先卸载它。Visual Studio运行器现在只通过NuGet分发。要删除它,进入工具>扩展和更新。滚动到列表的底部,如果安装了xUnit.net,则卸载它。这将迫使您重新启动Visual Studio。

如果您在发现或运行测试时遇到问题,那么您可能是Visual Studio中已损坏的运行器缓存的受害者。要清除此缓存,请关闭VisualStudio的所有实例,然后删除文件夹%TEMP%\VisualStudioTestExplorerExtensions。还要确保你的项目只链接到Visual Studio运行程序NuGet包的单个版本。

下面的步骤对我很有效:

(只有当你怀疑你的机器上有严重的混乱时-通常更常见的情况是visual studio集成还没有安装)

做DEL %TEMP%\VisualStudioTestExplorerExtensions建议:-

PS> del $env:TEMP\VisualStudioTestExplorerExtensions

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 Close Test Explorer <- this was the missing bit for me Re-open Test Explorer (Alt-S,W,T) Run All tests (Ctrl R, A)

我尝试了上面的大部分建议,但都没用。以我为例,我在一个团队中,为其他开发人员提供相同解决方案的测试。所以,我试图删除我的。vs文件夹,但运气也不好。

我最终完全删除了我的本地文件夹,并重新克隆了repo。这为我解决了问题。

这也可能是由于构建配置中当前平台项目的构建复选框未被选中。 单击Build | Configuration manager,然后确保测试项目在您正在使用的平台的Build列中有一个勾号(例如'x86')。

这绝对是对我有效的解决方案。

I Cleared Temp, %Temp% and Prefetch。然后尝试重新打开VS,并能够找到测试方法

还有一个原因可能导致测试资源管理器不显示任何测试,这与Visual Studio 2017 /为. net Core引入的新的可移植的.pdb文件格式有关,这可能会破坏一些VS工具。(背景:参见bug报告“Mono.”Cecil导致OutOfMemoryException与新的.csproj PDBs"。)

您的测试是否因为新的可移植.pdb(调试符号)格式而无法找到?

打开输出窗口。 将显示输出的下拉选择从更改为测试。 如果您看到如下输出(可能在每个测试中都重复一次),那么您就遇到了这个答案中描述的问题: 系统异常。OutOfMemoryException,异常转换<SignatureOfYourTestMethod> 数组尺寸超出支持范围。

如果是,请执行以下步骤解决问题:

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.