为什么 Visual Studio 2015/2017/2019 Test Runner 没有发现我的 xUnit v2 测试 [英] Why is the Visual Studio 2015/2017/2019 Test Runner not discovering my xUnit v2 tests
问题描述
更新:添加 2019 年;发现/运行器集成机制与 2017 & 相同2015 年,所以可能出错的关键是一样的.
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.
我已经阅读了 为什么 xUnit runner 不是找到我的测试,其中涵盖了 xUnit 永远无法找到您的测试的原因,但我的问题有所不同 - 我相信我的测试没有任何微妙之处;(他们曾在其他环境中工作过,这似乎只是我的机器)- Visual Studio 2015 [社区版] 中的 Visual Studio 测试运行程序根本没有显示任何我的测试.我没有做任何令人兴奋的事情;测试针对桌面上的 xUnit.net v2.
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.
推荐答案
从您的查询中消除发现异常;转到输出窗口 (Ctrl-Alt-O),然后将 show output from 下拉菜单 (Shift-Alt-S) 切换到 Tests 并确保没有发现例外
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
测试|测试设置|默认处理器架构如果您的测试是特定于 x86/x64 的并且发现正在触发与比特性相关的异常,即不是 AnyCpu,则可以提供帮助
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
正如本答案中所建议的(如果技术有帮助,请点赞)运行桌面控制台运行程序(instructions)可以是良好的交叉检查以消除其他可能性,例如损坏的配置文件:-
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:-
packagesxunit.runner.console.2.2.0 oolsxunit.console
注意 xunit.runner.console
包已被弃用 - 当你在 VS 中工作时,你将能够让 dotnet test
运行它们在 CI 上下文中也是如此
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
<小时>
阅读文档 - 这是全面的、最新的,包括故障排除信息和 PR:-
Go read the documentation - it's comprehensive, up to date, includes troubleshooting info and takes PRs:-
重要说明:如果您之前安装了 xUnit.net Visual Studio Runner VSIX (Extension),则必须先将其卸载.Visual Studio 运行器现在仅通过 NuGet 分发.要删除它,请转到工具 > 扩展和更新.滚动到列表底部,如果安装了 xUnit.net,请将其卸载.这将强制您重新启动 Visual Studio.
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.
如果您在发现或运行测试时遇到问题,您可能是 Visual Studio 中运行器缓存损坏的受害者.要清除此缓存,请关闭 Visual Studio 的所有实例,然后删除文件夹 %TEMP%VisualStudioTestExplorerExtensions
.还要确保您的项目仅链接到单个版本的 Visual Studio 运行程序 NuGet 包 (xunit.runner.visualstudio
).
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
).
以下步骤对我有用:
(仅当您怀疑您的机器出现严重问题时 - 通常更常见的情况是尚未安装 Visual Studio 集成)
按照建议执行 DEL %TEMP%VisualStudioTestExplorerExtensions
:-
PS>del $env:TEMPVisualStudioTestExplorerExtensions
在所有测试项目中安装 NuGet 包 xunit.runner.visualstudio
Install the NuGet Package xunit.runner.visualstudio
in all test projects
包:
.paketpaket add nuget xunit.runner.visualstudio -i
您需要在 paket.dependencies
中添加以下内容:
You need to end up with the following in your paket.dependencies
:
nuget xunit.runner.visualstudio version_in_path: true
注意 version_in_path: true
位很重要
Note the version_in_path: true
bit is important
Nuget:转到包管理器控制台 (Alt-T,N,O) 和
Nuget: Go to Package Manager Console (Alt-T,N,O) and
Install-Package xunit.runner.visualstudio)
重建以确保 xunit.runner
在输出目录中结束
Rebuild to make sure xunit.runner
ends up in the output dir
关闭测试浏览器<-这是我缺少的部分
Close Test Explorer <- this was the missing bit for me
重新打开测试资源管理器(Alt-S、W、T)
Re-open Test Explorer (Alt-S,W,T)
运行所有测试(Ctrl R、A)
这篇关于为什么 Visual Studio 2015/2017/2019 Test Runner 没有发现我的 xUnit v2 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!