简体   繁体   English

为什么 Visual Studio 2015/2017/2019 测试运行程序没有发现我的 xUnit v2 测试

[英]Why is the Visual Studio 2015/2017/2019 Test Runner not discovering my xUnit v2 tests

UPDATE: Adding a 2019;更新:添加 2019; the discovery/runner integration mechanism is same as per 2017 & 2015, so the key things that can go wrong are the same.发现/运行器集成机制与 2017 和 2015 相同,因此可能出错的关键问题是相同的。


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;我已经阅读了为什么 xUnit 运行程序找不到我的测试,这涵盖了 xUnit永远无法找到您的测试但我的问题不同的原因- 我相信我的测试没有任何微妙之处; (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. (他们在其他环境中工作过,这似乎只是我的机器) - Visual Studio 2015 [社区版] 中的 Visual Studio 测试运行程序根本没有显示我的任何测试。 I'm not doing anything remotely exciting;我没有做任何令人兴奋的事情; the tests target xUnit.net v2 on the Desktop.测试针对桌面上的 xUnit.net v2。

I've looked in the Output window and am not seeing anything in at all under Test in the Show output from tabs.我查看了“输出”窗口,但在“显示选项卡的输出”中的“测试”下根本看不到任何内容。

  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转到输出窗口 (Ctrl-Alt-O),然后将显示输出从下拉 (Shift-Alt-S) 切换到测试并确保没有发现异常

  2. Test|Test settings|Default processor architecture can help if your tests are x86/x64 specific and discovery is triggering bittedness-related exceptions, ie not AnyCpu测试|测试设置|如果您的测试是特定于 x86/x64 并且发现正在触发与比特性相关的异常(即不是AnyCpu ),则默认处理器架构会有所帮助

  3. 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, eg 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注意xunit.runner.console包已被弃用 - 当您在 VS 中工作时,您也可以让dotnet test在 CI 上下文中运行它们


Go read the documentation - it's comprehensive, up to date, includes troubleshooting info and takes PRs:- 去阅读文档- 它是全面的,最新的,包括故障排除信息并需要 PR:-

Important note: If you've previously installed the xUnit.net Visual Studio Runner VSIX (Extension), you must uninstall it first.重要提示:如果您之前安装了 xUnit.net Visual Studio Runner VSIX(扩展),则必须先将其卸载。 The Visual Studio runner is only distributed via NuGet now. Visual Studio 运行程序现在仅通过 NuGet 分发。 To remove it, to go Tools > Extensions and Updates .要删除它,请转到Tools > Extensions and Updates Scroll to the bottom of the list, and if xUnit.net is installed, uninstall it.滚动到列表底部,如果安装了 xUnit.net,请将其卸载。 This will force you to restart Visual Studio.这将强制您重新启动 Visual Studio。

If you're having problems discovering or running tests, you may be a victim of a corrupted runner cache inside Visual Studio.如果您在发现或运行测试时遇到问题,您可能是 Visual Studio 中损坏的运行程序缓存的受害者。 To clear this cache, shut down all instances of Visual Studio, then delete the folder %TEMP%\VisualStudioTestExplorerExtensions .要清除此缓存,请关闭 Visual Studio 的所有实例,然后删除文件夹%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 运行程序 NuGet 包 ( 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) (仅当您怀疑您的机器上存在严重混乱时 - 通常更常见的情况是尚未安装 Visual Studio 集成)

Do the DEL %TEMP%\VisualStudioTestExplorerExtensions as advised :-按照建议执行DEL %TEMP%\VisualStudioTestExplorerExtensions :-

PS> del $env:TEMP\VisualStudioTestExplorerExtensions
  1. Install the NuGet Package xunit.runner.visualstudio in all test projects在所有测试项目中安装 NuGet 包xunit.runner.visualstudio

    • Paket:包:

       .paket\paket add nuget xunit.runner.visualstudio -i

      You need to end up with the following in your paket.dependencies :您需要在paket.dependencies中完成以下内容

       nuget xunit.runner.visualstudio version_in_path: true

      Note the version_in_path: true bit is important注意version_in_path: true位很重要

    • Nuget: Go to Package Manager Console (Alt-T,N,O) and Nuget:转到包管理器控制台(Alt-T、N、O)和

      Install-Package xunit.runner.visualstudio

    Rebuild to make sure xunit.runner ends up in the output dir重建以确保xunit.runner在输出目录中结束

  2. Close Test Explorer <- this was the missing bit for me关闭测试资源管理器<- 这对我来说是缺失的部分

  3. Re-open Test Explorer (Alt-S,W,T)重新打开测试资源管理器 (Alt-S,W,T)

  4. Run All tests (Ctrl R, A)运行所有测试 (Ctrl R, A)

None of the above solutions worked for me (dotnetcore 1.1, VS2017).上述解决方案都不适合我(dotnetcore 1.1,VS2017)。 Here's what fixed it:这是修复它的方法:

  1. Add NuGet Package Microsoft.TestPlatform.TestHost添加 NuGet 包Microsoft.TestPlatform.TestHost
  2. Add NuGet Package Microsoft.NET.Test.Sdk添加 NuGet 包Microsoft.NET.Test.Sdk

Those are in addition to these packages I installed prior:这些是我之前安装的这些软件包的补充

  • xunit (2.3.0-beta1-build3642) xunit (2.3.0-beta1-build3642)
  • xunit.runner.visualstudio (2.3.0-beta1-build1309) xunit.runner.visualstudio (2.3.0-beta1-build1309)

I had to change the Test Settings after changing the test projects CPU to x64.将测试项目 CPU 更改为 x64 后,我不得不更改测试设置。 Then the tests where detected again.然后再次检测到测试。

建筑学

为测试项目安装xunit.runner.visualstudio

确保您的测试类是public

Follow this steps :请按照以下步骤操作:

  1. Update your MsTest.TestAdapter and MsTest.TestFramework dll's from nugget package manager .nugget package manager更新您的MsTest.TestAdapterMsTest.TestFramework dll's
  2. Clean your solution清洁您的解决方案
  3. Build your solution.构建您的解决方案。

I've been struggling with this all afternoon whilst working with an ASP Core project and xUnit 2.2.0.在使用 ASP Core 项目和 xUnit 2.2.0 时,我整个下午都在为此苦苦挣扎。 The solution for me was adding a reference to Microsoft.DotNet.InternalAbstractions我的解决方案是添加对Microsoft.DotNet.InternalAbstractions的引用

I found this out when trying to run the test project manually with dotnet test which failed but reported that InternalAbstractions was missing.我在尝试使用dotnet test手动运行测试项目时发现了这一点,该测试失败但报告缺少InternalAbstractions I did not see this error in the test output window when the auto discovery failed.自动发现失败时,我在测试输出窗口中没有看到此错误。 The only info I saw in the discovery window was a return code, which didn't mean anything to me at the time, but in hindsight was probably indicating an error.我在发现窗口中看到的唯一信息是返回码,当时这对我来说没有任何意义,但事后看来可能表明存在错误。

这发生在我身上几次 - 当我清理项目并再次构建它时,它往往会很好。

I had the same issue with Visual Studio 2019. Just Installed the following NuGet packages and the issue was solved.我在使用 Visual Studio 2019 时遇到了同样的问题。刚刚安装了以下 NuGet 包,问题就解决了。

1). 1)。 xUnit xUnit

2). 2)。 xunit.runner.visualstudio xunit.runner.visualstudio

3). 3)。 Microsoft.TestPlatform.TestHost Microsoft.TestPlatform.TestHost

4). 4)。 Microsoft.NET.Test.Sdk Microsoft.NET.Test.Sdk

After spending 2 days... none of the above worked for me.花了 2 天后......以上都不适合我。 The only "solution" was: Go to project properties -> Build Tab.唯一的“解决方案”是:转到项目属性-> 构建选项卡。 Then click Advanced button on the right bottom corner of the pane.然后单击窗格右下角的高级按钮。 Change "Debug Info:" to "full" and click OK.将“调试信息:”更改为“完整”,然后单击“确定”。

Here are the screen shots:以下是屏幕截图: 在此处输入图像描述

在此处输入图像描述 在此处输入图像描述

The reason in my case was the target build was not the same between project debugger and test runner.就我而言,原因是项目调试器和测试运行器之间的目标构建不同。 To unify those elements:统一这些元素:

  1. Test>Test Settings>Default Processor Architecture.测试>测试设置>默认处理器架构。 then select either X64 or X86.然后选择 X64 或 X86。
  2. Project>(your project)Properties>Build(tab)>platform target.项目>(您的项目)属性>构建(选项卡)>平台目标。

After they are identical, rebuild your solution then test methods will appear for you.在它们相同后,重新构建您的解决方案,然后将为您显示测试方法。

I am using xUnit 2.2.0.我正在使用 xUnit 2.2.0。

My issue was my solution was not able to find certain dlls and app.config was trying to resolve them.我的问题是我的解决方案无法找到某些 dll,而app.config正在尝试解决它们。 The error was not showing up in the test output window in Visual Studio.该错误未显示在 Visual Studio 的测试输出窗口中。

I was able to identify the error when I installed xunit.runner.console and tried to run the tests through command line.当我安装xunit.runner.console并尝试通过命令行运行测试时,我能够识别错误。

How to run xunit tests in CLI . 如何在 CLI 中运行 xunit 测试

I can provide a solution for an edge case I ran into a few days ago.我可以为几天前遇到的边缘情况提供解决方案。 It's not gonna be the solution that fits all of the scenarios described above, however, for the edge case I had it fixed it.它不会是适合上述所有场景的解决方案,但是,对于边缘情况,我已经修复了它。

I had the same issue with most recent VS 2017 (version 15.5.7) and XUnit 2.3.1.我在最新的 VS 2017(版本 15.5.7)和 XUnit 2.3.1 中遇到了同样的问题。 The xunit.runner.visualstudio package was installed, however, the tests didn't show up in VisualStudio's built-in test explorer. xunit.runner.visualstudio 包已安装,但是测试并未显示在 VisualStudio 的内置测试资源管理器中。

I was working on a legacy project that was targeting .NET framework 4.5.我正在处理一个针对 .NET 框架 4.5 的遗留项目。 However, beginning with version 2.2.但是,从 2.2 版开始。 XUnit does not support .NET frameworks lower thant 4.5.2 (see Release Notes - XUnit 2.2: February 19, 2017 XUnit 不支持低于 4.5.2 的 .NET 框架(请参阅发行说明 - XUnit 2.2:2017 年 2 月 19 日

Changing the test project's target framework to a version >= 4.5.2 worked for me.将测试项目的目标框架更改为 >= 4.5.2 对我有用。 You don't have to change the project's version that you're testing, it's just about the test project itself.您不必更改正在测试的项目版本,只需更改测试项目本身即可。

Ran into a similar problem with VS not discovering test methods.遇到与 VS 未发现测试方法类似的问题。 In my case I had the static keyword with the method, which I removed and it worked.在我的情况下,我在方法中使用了 static 关键字,我删除了它并且它起作用了。

[TestMethod]

Before: public static void Test1()

After: public void Test1()

This can also be due to the build check box not being ticked for the current platform project in the build configuration.这也可能是由于构建配置中当前平台项目的构建复选框未选中。 Click Build |点击构建 | Configuration manager, then make sure the test projects have a tick in the build column for the platform that you're using (for example 'x86').配置管理器,然后确保测试项目在您正在使用的平台的构建列中有一个勾号(例如“x86”)。

This was definitely the solution that worked for me.这绝对是对我有用的解决方案。

Do make sure that you haven't written your unit tests in a .NET Standard 2.0 Class Library.请确保您没有在 .NET Standard 2.0 类库中编写单元测试。 The visualstudio runner does not support running tests in netstandard2.0 class libraries at the time of this writing.在撰写本文时,visualstudio 运行程序不支持在 netstandard2.0 类库中运行测试。

Check here for the Test Runner Compatibility matrix:在此处查看测试运行器兼容性矩阵:

https://xunit.net https://xunit.net

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.还有一个原因可能导致测试资源管理器不显示任何测试,这与 Visual Studio 2017 / for .NET Core 引入的新的可移植.pdb文件格式有关,这可能会破坏一些 VS 工具。 (Background: See the bug report "Mono.Cecil causes OutOfMemoryException with new .csproj PDBs" .) (背景:请参阅错误报告“Mono.Cecil 使用新的 .csproj PDB 导致 OutOfMemoryException” 。)

Are your tests not found because of the new portable .pdb (debug symbols) format?是否因为新的可移植.pdb (调试符号)格式而找不到您的测试?

  • Open the Output window.打开输出窗口。
  • Change drop-down selection for Show output from to Tests .Show output 的下拉选择从更改为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 ).打开测试项目的属性(在解决方案资源管理器中选择测试项目并按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 .在标记为Debugging information的下拉列表中,选择nonepdb-onlyfull ,但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.如果您想更加确定,请转到您的测试项目的输出目录并在重建之前清理所有.pdb文件。 Now your tests should be back.现在你的测试应该回来了。

In my case, I had 2 different test projects in the solution.就我而言,我在解决方案中有 2 个不同的测试项目。 Project 1 tests could be found, but Project 2 tests could not.可以找到项目 1 的测试,但找不到项目 2 的测试。 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.我发现首先卸载测试项目 1,然后关闭 VS > 清除我的临时文件 > 重新打开解决方案 > 重建,允许 VS 发现我的项目 2 测试。

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 :).扭结可以稍后解决:)。

I was suffering from this problem for long times.我被这个问题困扰了很长时间。

  • I had about 100 projects different version was deployed in different server.我在不同的服务器上部署了大约 100 个不同版本的项目。

  • Updating xunit from 2.2.0 to 2.3.1 was not a solution because build was failing in 2.3.1.xunit从 2.2.0 更新到 2.3.1 不是解决方案,因为在 2.3.1 中构建失败。

Then I just updated xunit.runner.visualstudio to 2.3.1 and everything started to work fine.然后我刚刚将xunit.runner.visualstudio更新到2.3.1 ,一切都开始正常了。 I have used this command in my package manager console to updated my xunit.runner.visualstudio package我在我的包管理器控制台中使用了这个命令来更新我的 xunit.runner.visualstudio 包

Get-Project ComapanyName.ProjectName.*.Tests | Install-Package xunit.runner.visualstudio -Version 2.3.1
  1. Close all Visual Studio instances关闭所有 Visual Studio 实例
  2. Go to %TEMP%\VisualStudioTestExplorerExtensions\转到 %TEMP%\VisualStudioTestExplorerExtensions\
  3. Delete specrun related folders删除 specrun 相关文件夹
  4. Try again再试一次

let me know, thanks让我知道,谢谢

I hope my answer will be helpful for some of you: In most of the cases when my unit tests were not discovered I had to change the the test class access modifier to public.我希望我的回答对你们中的一些人有所帮助:在大多数情况下,当我的单元测试未被发现时,我不得不将测试类访问修饰符更改为 public。 When add a new class (Shift+Alt+C) the default access modifier is internal and most of the time I forget to change it.当添加一个新类(Shift+Alt+C)时,默认访问修饰符是内部的,大多数时候我忘记更改它。

The most common culprit for me has been Visual Studio trying to run the tests using a different architecture than the library it's testing.对我来说,最常见的罪魁祸首是 Visual Studio 试图使用与其测试的库不同的架构来运行测试。 Unfortunately there are multiple places where it seems this can go wrong.不幸的是,有多个地方似乎会出错。

In VS 2017, try creating a Run Settings file, eg Default.runsettings in your test project.在 VS 2017 中,尝试在您的测试项目中创建一个运行设置文件,例如Default.runsettings If your main lib is x64, the contents should be:如果您的主库是 x64,则内容应为:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <RunConfiguration>
    <TargetPlatform>x64</TargetPlatform>
  </RunConfiguration>
</RunSettings>

Then choose this file from Test -> Test Settings -> Select Test Settings File.然后从测试 -> 测试设置 -> 选择测试设置文件中选择此文件。

Then, under Test -> Test Settings, Default Processor Architecture, choose the correct architecture again.然后,在测试 -> 测试设置,默认处理器架构下,再次选择正确的架构。

Be sure to Clean and Build the entire solution.请务必清理并构建整个解决方案。 You may need to close and reopen the Test Explorer window.您可能需要关闭并重新打开测试资源管理器窗口。 Look for any additional errors in the Output -> Test window, for more clues about incorrect architecture types.在 Output -> Test 窗口中查找任何其他错误,以获取有关不正确架构类型的更多线索。

FYI additional Test Settings entries can be found here .仅供参考,可以在此处找到其他测试设置条目。

Happend to me when i took my first first walking attempts with IntelliTest in VS 2017.当我在 VS 2017 中使用 IntelliTest 进行第一次步行尝试时,这件事发生在我身上。

Sometimes, when the test project gets auto-created by IntelliTest, the assembly reference to Microsoft.ExtendedReflection ( ...\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\Microsoft\Pex\Microsoft.ExtendedReflection.dll ) is missing.有时,当 IntelliTest 自动创建测试项目时,程序集引用Microsoft.ExtendedReflection ( ...\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\Microsoft\Pex\Microsoft .ExtendedReflection.dll )丢失。 When added, the generated Tests will show up in test explorer after recompile.添加后,生成的测试将在重新编译后显示在测试资源管理器中。

Disclaimer: it is not about xunit with visual studio 2015, but Visual Studio 2017 with a UWP unit test application (MSTest).免责声明:这与带有 Visual Studio 2015 的 xunit 无关,而是带有 UWP 单元测试应用程序 (MSTest) 的 Visual Studio 2017。 I got to this thread searching the same thing so maybe someone else will do the same :)我到这个线程搜索同样的事情,所以也许其他人会做同样的事情:)

The solution for me was to update the nuget packages for MSTest.TestAdapter and MSTest.TestFramework.我的解决方案是更新 MSTest.TestAdapter 和 MSTest.TestFramework 的 nuget 包。 It seems that when you create a unit test app for UWP you don't automatically get the latest versions.似乎当您为 UWP 创建单元测试应用程序时,您不会自动获得最新版本。

通过安装 nuget xunit.runner.visualstudio 解决了我的问题

In my case I have multiple test projects in the same solution, and only one of the projects was not displaying the "Test Explorer"在我的情况下,我在同一个解决方案中有多个测试项目,只有一个项目没有显示“测试资源管理器”

I went to the "Manage Nuget Package for Solution" by right-clicking on the solution.我通过右键单击解决方案转到“管理解决方案的 Nuget 包”。

I noticed under the "Consolidate" tab there was some "Test" nuget packages that were out of sync between the projects.我注意到在“合并”选项卡下有一些“测试”nuget 包在项目之间不同步。 I clicked on "Install" and my missing tests showed up.我点击了“安装”,我丢失的测试出现了。

I tried most of the suggestions above and nothing worked.我尝试了上面的大部分建议,但没有任何效果。 In my case, I'm on a team and tests were appearing for other devs for the same solution.就我而言,我在一个团队中,并且正在为其他开发人员提供相同解决方案的测试。 So, I attempted just deleting my .vs folder, but no luck there either.所以,我试图删除我的 .vs 文件夹,但也没有运气。

I ended up deleting my local folder entirely and re-cloning the repo.我最终完全删除了我的本地文件夹并重新克隆了 repo。 That solved it for me.这为我解决了它。

Here is the solution that worked for us.这是对我们有用的解决方案。 Not the best but maybe one can benefit.不是最好的,但也许可以受益。

Background:背景:

  • Our scripts were developed with VS 2013 and used NUnit VS Adapter 2.1..我们的脚本是使用 VS 2013 开发的,并使用 NUnit VS Adapter 2.1..
  • Recently we migrated to VS 2017 and when open the same solution - test wouldn't show in the Test Explorer最近我们迁移到 VS 2017,当打开相同的解决方案时 - 测试不会显示在测试资源管理器中

Upon Build we would see this message:在构建时,我们会看到以下消息:

[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

Solution (temporary):解决方案(临时):

  • Uninstall NUnit Adapter 3.10...卸载 NUnit 适配器 3.10...
  • Install NUnit VS Adapter 2.1..安装 NUnit VS 适配器 2.1..

Now the Tests are shown.现在显示测试。

Also check if a completely empty app.config file (completely blank with absolutely no markup) is within the test project.还要检查测试项目中是否有一个完全空的 app.config 文件(完全空白,绝对没有标记)。 This was the culprit in my case.这是我的罪魁祸首。

In my case, I created a new "Solution Configuration" like shown in the image.就我而言,我创建了一个新的“解决方案配置”,如图所示。 So when I select my custom one as "Prod", it doesnt recognize TestMehods for some reason.因此,当我将自定义选项选为“Prod”时,由于某种原因,它无法识别 TestMehods。 Changing back to "Debug" solves the problem改回“调试”可以解决问题

在此处输入图像描述

我不知道你们中的一些人是否也使用 JustMock,但我必须在 VS 2017 中禁用分析器才能进行测试检测。

I had many projects of different type in my solution and I could not run the Xunit test project.我的解决方案中有许多不同类型的项目,我无法运行 Xunit 测试项目。 I unloaded all of them except my Xunit project and then rebuild the solution the tests appeared in visual studio and I could run them.我卸载了除我的 Xunit 项目之外的所有这些,然后重建了测试出现在 Visual Studio 中的解决方案,我可以运行它们。

当您将 VS2015 移动到 VS2017 以在测试资源管理器中发现测试时,您需要更新所有包。

I Cleared Temp, %Temp% and Prefetch.我清除了 Temp、%Temp% 和 Prefetch。 Then tried reopening VS and was able to find the test methods然后尝试重新打开VS并能够找到测试方法

I have test project A and B. Tests in Project A where discovered but the Discovery never stopped for B. I had to manually kill TestHost to make stop.我有测试项目 A 和 B。项目 A 中的测试发现但发现从未停止 B。我不得不手动终止 TestHost 才能停止。

I did a lot of things this page describes even to the point that I'm unsure as to wheter this was the solution.我做了很多本页描述的事情,甚至到了我不确定这是否是解决方案的地步。

Now it worked and the thing I did was to open the Solution and NOT have the Test Explorer up.现在它起作用了,我所做的就是打开解决方案而不是启动测试资源管理器。 Instead I just checked the Output window for Tests and I could see the discovery process end and the number of test where equal to A+B.相反,我只是检查了测试的输出窗口,我可以看到发现过程结束并且测试数量等于 A+B。 After this, I opened the Test Explorer and then both A and B where present.在此之后,我打开了测试资源管理器,然后打开了 A 和 B。 So:所以:

Uninstall and Install the latest xUnit stuff correctly.正确卸载并安装最新的 xUnit。 Delete the %temp% as mentioned above, Add NuGet Package "Microsoft.TestPlatform.TestHost" Add NuGet Package "Microsoft.NET.Test.Sdk", restart but only check the Tests Output.如上所述删除 %temp%,添加 NuGet 包“Microsoft.TestPlatform.TestHost” 添加 NuGet 包“Microsoft.NET.Test.Sdk”,重新启动但只检查测试输出。 If it works u'll see如果它有效,你会看到

将您的测试类设为公开并将注释添加为 [TestClass]

Right click on Test project and select Properties.右键单击测试项目并选择属性。 Change Target framework property from 1.1 to something else (I used 3.1) and everything will run as 1.1 isnt covered anymore :P将 Target 框架属性从 1.1 更改为其他内容(我使用的是 3.1),所有内容都将运行为 1.1 不再涵盖:P

Open Outputs -> Tests and see what the error is.打开输出 -> 测试并查看错误是什么。 In my case, I had this error message:就我而言,我收到了以下错误消息:

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

After installing .Net SDK 5.0, tests worked immediately: https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-5.0.402-windows-x64-installer安装 .Net SDK 5.0 后,测试立即生效: https ://dotnet.microsoft.com/download/dotnet/thank-you/sdk-5.0.402-windows-x64-installer

It was that easy for me - the class which contains the test methods must be public .这对我来说很容易——包含测试方法的类必须是公共的。 :) :)

check the type of test.cs files in property window and it is c# compiler.在属性窗口中检查 test.cs 文件的类型,它是 c# 编译器。 in my case i have accidentally changed it to the embedresource and faced this issue.就我而言,我不小心将其更改为 embedresource 并遇到了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 用于DNX和XUnit的Visual Studio测试运行器的替代产品? - Alternatives to Visual Studio test runner for DNX and XUnit? Visual Studio 2019 突然需要 nuget Microsoft.NET.Test.Sdk 来运行 xUnit 单元测试 - Visual Studio 2019 suddenly requires nuget Microsoft.NET.Test.Sdk to run xUnit unit-tests Visual Studio 2015测试运行器中的“句柄无效”异常 - “The handle is invalid” exception in Visual Studio 2015 test runner 为什么.NET Core(dnxcore50)xUnit测试在VS2015测试资源管理器中不可见? - Why .NET Core (dnxcore50) xUnit Tests are not visible in VS2015 Test Explorer? 在 Visual Studio 2022 的测试资源管理器中未检测到“未找到要运行的测试”Xunit 测试 - "No tests found to run" Xunit test not detected in Test explorer, Visual Studio 2022 如何在 Visual Studio 2017/2019 中为特定目标框架运行单元测试? - How do you run unit tests for a specific target framework in Visual Studio 2017/2019? 使用.Net Framework v4.8和Visual Studio 2019查询TFS 2015源代码存储库DateTime属性 - Querying TFS 2015 Source Code Repository DateTime Properties with .Net Framework v4.8 and Visual Studio 2019 Visual Studio 2015 CodedUI测试无法在2017年签入后加载2013年dll - Visual Studio 2015 CodedUI Test can't load 2013 dll after 2017 check in 将Visual Studio 2015项目转换为Visual Studio 2017? - Convert Visual Studio 2015 project to Visual Studio 2017? xUnit v2 IUseFixture &lt;&gt;替换 - xUnit v2 IUseFixture<> replacement
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM