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

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

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

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

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


当前回答

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.

其他回答

如果你正在使用NUnit而不是MSTest,那么你将需要NUnit 2测试适配器或NUnit 3测试适配器(Visual Studio≥2012/2013)。

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

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

"TestClass attribute defined on non-public class"

值得一提的是,有时用户文件夹中的NUnit Test Adapter文件会损坏 C: \[用户]用户当地\ AppData \ \ Temp \ VisualStudioTestExplorerExtensions \ NUnit3TestAdapter.3.8.0 /构建/ net35 / NUnit3.TestAdapter.dll 在Windows 10上,这会导致测试资源管理器停止工作。

我也有同样的症状

请确保您通过工具-扩展和更新安装了正确的Visual Studio扩展。在我的案例中,我必须从Online选项中安装XUnit和Specflow。

然后清洗溶液,重新构建。

如果仍然没有帮助,清除您的temp目录(在开始菜单搜索中搜索%temp%并删除temp中的所有内容)

然后最后尝试卸载Resharper,这最终解决了我的问题。

根据安装的运行时,您可能需要选择:

[右键单击测试项目]->属性->构建->平台目标-例如x86

将其设置为x64会导致“The framework 'Microsoft.NETCore. net”App', version '3.1.0' was not found."错误在测试错误输出。