我目前正在开发一个有32个单元测试的解决方案。我一直在使用resharper测试运行器-它工作得很好。所有测试都在运行,所有测试都显示正确的测试结果。

但是,在使用Visual Studio测试资源管理器时,测试未运行。

测试资源管理器正在显示所有单元测试,但一旦单击“全部运行”,所有测试都将变成灰色,并且不显示测试运行的结果:

所有测试类都是公共的 所有测试类都声明了[TestClass]属性 所有测试方法都使用[TestMethod]属性 生产力代码和测试项目都是针对。net 3.5的。 我已经尝试清洁构建我的解决方案,和/或删除所有obj, bin,调试和发布文件夹

我很感激任何能解释这种行为的提示。


当前回答

我不得不改变我的异步测试方法,以返回任务而不是void。

然后,测试在“测试资源管理器”中处于活动状态并可运行。

其他回答

我有这个问题,原来我在测试类前漏掉了“public”。

在“显示来自:测试的输出”下对此有一个警告

"TestClass attribute defined on non-public class"

I found that in the project it was not referencing the Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly. Instead, it was referencing Microsoft.VisualStudio.TestPlatform.TestFramework and Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions. When I removed those two references and added the reference to the Microsoft.VisualStudio.QualityTools.UnitTestFramework assembly the tests that were previously marked with the blue exclamation point suddenly became active and started working.

Nuget已经解决了这个问题

检查你的项目文件中不同版本的NUnit的引用:

在我的例子中,我已经安装了NUnit和NUnit3TestAdapter的3.11.0版本,但是在项目文件中有对2.6.4版本的旧引用,这些引用没有随着新的安装被删除。

解决方案(建议修复引用问题,请参阅文档): 重新安装NUnit和NUnit3TestAdapter,这修复了我的项目中的引用。

PM> Update-Package NUnit -reinstall
...
PM> Update-Package NUnit3TestAdapter -reinstall

解决方案2(如果重新安装没有修复引用): 卸载并安装NUnit和NUnit3TestAdapter。

PM> Uninstall-Package NUnit
...
PM> Uninstall-Package NUnit3TestAdapter
...
PM> Install-Package NUnit
...
PM> Install-Package NUnit3TestAdapter

我遇到过这个问题,对我来说,这是由于有多个不同版本的测试项目造成的:

MSTest。TestAdapter MSTest。TestFramework

巩固项目的nuget包,使他们是相同的解决了我的问题。