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


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

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


当前回答

这是对我们有效的解决方案。不是最好的,但也许能从中受益。

背景:

我们的脚本是用VS 2013开发的,使用NUnit VS Adapter 2.1.. 最近我们迁移到VS 2017,当打开相同的解决方案时,测试将不会在测试资源管理器中显示

在构建时,我们会看到这样的消息:

[Informational] NUnit Adapter 3.10.0.21: Test discovery starting
[Informational] Assembly contains no NUnit 3.0 tests: C:\ihealautomatedTests\SeleniumTest\bin\x86\Debug\SeleniumTest.dll
[Informational] NUnit Adapter 3.10.0.21: Test discovery complete

解决方案(临时):

卸载NUnit Adapter 3.10 安装NUnit VS适配器

现在显示测试。

其他回答

在将测试项目的CPU更改为x64后,我不得不更改测试设置。 然后测试再次检测。

免责声明:这不是关于visual studio 2015的xunit,而是visual studio 2017的UWP单元测试应用程序(MSTest)。我到这个线程搜索同样的东西,所以也许其他人会做同样的事情:)

我的解决方案是更新MSTest的nuget包。TestAdapter和mste . testframework。当你为UWP创建一个单元测试应用程序时,你似乎不会自动获得最新的版本。

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)

遵循以下步骤:

更新你的MsTest。TestAdapter和MsTest。TestFramework dll来自nugget包管理器。 清洗溶液 构建您的解决方案。

打开输出->测试并查看错误是什么。在我的例子中,我有这样的错误消息:

The framework 'Microsoft.AspNetCore.App', version '5.0.0' (x64) was not found.

在安装。net SDK 5.0后,测试立即生效:https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-5.0.402-windows-x64-installer