简体   繁体   English

Visual Studio 15.8.1 未运行 MS 单元测试

[英]Visual Studio 15.8.1 not running MS unit tests

When I updated Visual Studio to the latest version, 1 of my test projects stopped running tests and outputted this message:当我将 Visual Studio 更新到最新版本时,我的 1 个测试项目停止运行测试并输出以下消息:

Test project {} does not reference any .NET NuGet adapter.测试项目 {} 未引用任何 .NET NuGet 适配器。 Test discovery or execution might not work for this project.测试发现或执行可能不适用于此项目。 It is recommended to reference NuGet test adapters in each test project in the solution.建议在解决方案中的每个测试项目中引用 NuGet 测试适配器。

UPDATED: I was using MS Test as opposed to any other test frameworks like Nunit or Xunit.更新:我使用的是 MS Test,而不是任何其他测试框架,如 Nunit 或 Xunit。

Ok, you can add Nuget packages as asked.好的,您可以按要求添加 Nuget 包。 But you can also try to disable the following setting (Tools->Options->Test): "For improved performance, only use test adapters in test assembly folder or as specified in runsettings file" .但是您也可以尝试禁用以下设置(工具->选项->测试): “为了提高性能,请仅使用测试程序集文件夹中或运行设置文件中指定的测试适配器”

Let me know if it works for you.请让我知道这对你有没有用。

I had to add the following Nuget packages:我必须添加以下 Nuget 包:

MSTest.TestAdapter
MSTest.TestFramework
Microsoft.NET.Test.Sdk

Visual Studio release notes Visual Studio 发行说明

If you are using MS Test, try installing如果您使用的是 MS Test,请尝试安装

MSTest.TestAdapter via nuget or MSTest.TestAdapter通过 nuget 或

if you are using nunit, install如果您使用的是 nunit,请安装

NUnit3TestAdapter latest versions via nuget. NUnit3TestAdapter通过 nuget 的最新版本。

After installing please restart the visual studio and then you can see the tests running.安装后请重新启动visual studio,然后您可以看到测试正在运行。

I had the same issue and none of the answers above worked.我遇到了同样的问题,上面的答案都没有奏效。 Installing NUnit3TestAdapter V3.10.0 fixed it.安装NUnit3TestAdapter V3.10.0修复了它。

I had a very similar issue recently with xUnit, the same outcome, however my fix was due to the fact that previously with lower versions of Microsoft.NET.Test.Sdk you didn't need XUnit.Runner.VisualStudio explicitly installed.我最近在 xUnit 上遇到了一个非常相似的问题,结果相同,但是我的修复是因为以前使用较低版本的 Microsoft.NET.Test.Sdk 您不需要显式安装 XUnit.Runner.VisualStudio。

When I updated my Microsoft.NET.Test.Sdk to version 15.9.0 it stopped allowing tests to run until I installed the XUnit.Runner.VisualStudio Nuget.当我将 Microsoft.NET.Test.Sdk 更新到版本 15.9.0 时,它停止允许测试运行,直到我安装了 XUnit.Runner.VisualStudio Nuget。

Now, This may seem blatantly obvious, but, previously it would cope without it and still work.现在,这可能看起来很明显,但是,以前它可以在没有它的情况下处理并且仍然有效。 Now, it does not.现在,它没有。 The same will probably be true of other test platforms.其他测试平台可能也是如此。 It worked for me.它对我有用。

My reputation score does not currently allow me to add this as a comment to the accepted answer.我的声誉分数目前不允许我将此作为评论添加到已接受的答案中。 For reference, I've appended version numbers to the nuget packages referenced in csharpsql's answer :作为参考,我已将版本号附加到csharpsql 的回答中引用的 nuget 包中:

MSTest.TestAdapter v1.3.2
MSTest.TestFramework v1.3.2
Microsoft.NET.Test.Sdk v15.9.0

I know that it is stupid, but for me nothing from earlier answers were working.我知道这很愚蠢,但对我来说,早期的答案没有任何作用。 After that I just restart my computer and everything is working correctly :) (My proble was that one day everything was working correctly and next day it stopped working)之后我只是重新启动我的计算机,一切正常:)(我的问题是有一天一切正常,第二天它停止工作)

对我来说,我花了几个小时,尝试了一切,才发现我只是忘记在单元测试方法上添加 [TestMethod] 指令,我觉得很愚蠢。

I was trying to run an existing project.我试图运行一个现有的项目。 I had the .NET Core SDK 3.3 installed, but did not have 2.1 installed.我安装了 .NET Core SDK 3.3,但没有安装 2.1。 This was causing the tests to silently fail.这导致测试无声无息地失败。

I ran into this problem too (in VS 2019), which can be found all over the web.我也遇到了这个问题(在 VS 2019 中),可以在整个网络上找到。 I also support @csharpsql's simple solution.我也支持@csharpsql 的简单解决方案。 I also couldn't directly comment (how annoying Stack Overflow!)我也无法直接评论(堆栈溢出多烦人!)

I had used 'Remove unused references' in VS.我在 VS 中使用了“删除未使用的引用”。 I did have to restart VS to get the references removed from view.我确实必须重新启动 VS 才能从视图中删除引用。 Cleaning and rebuilding posed no problem.清洁和重建没有问题。

But running all tests from the Test Explorer reported 'Not run' on all tests, without any explanation or error message.但是从测试资源管理器运行所有测试在所有测试中报告“未运行”,没有任何解释或错误消息。 Very annoying.很烦人。

After finding the suggestion here I started experimenting with re-adding the latest versions of those 3 references.在这里找到建议后,我开始尝试重新添加这 3 个引用的最新版本。 That solved my problem.那解决了我的问题。 I just remains annoying this unnecessary problem occurs!我只是很烦这个不必要的问题发生!

Since its just a checkbox, Ive tried disabling the following setting before anything else, and it worked!由于它只是一个复选框,因此我尝试在其他任何设置之前禁用以下设置,并且它起作用了!

Tools -> Options -> Test -> "For improved performance, only use test adapters in test assembly folder or as specified in runsettings file"工具->选项->测试-> “为了提高性能,请仅使用测试程序集文件夹中或运行设置文件中指定的测试适配器”

Adding NuGet packages doesn't work for me.添加 NuGet 包对我不起作用。

Disable the following setting (Tools->Options->Test): "For improved performance, only use test adapters in test assembly folder or as specified in runsettings file" works.禁用以下设置(工具->选项->测试):“为了提高性能,仅使用测试程序集文件夹中的测试适配器或运行设置文件中指定的测试适配器”有效。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM