我目前正在开发一个有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.

其他回答

在vs2019干净安装后也有同样的问题。发现测试,但运行时未显示“发生意外错误”。通过设置x64而不是默认选择的x86来修复。

我有不同版本的NUnit(3.11.0)和NunitTestAdapter (3.12.0) nuget包。当我将NUnit更新到3.12.0时,Visual Studio运行了测试。

我添加了<PackageReference Include="NUnit3TestAdapter" Version="3.16.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime;构建;本机;contentfiles;分析程序;buildtransitive < / IncludeAssets > < / PackageReference >

在我的测试中。csproj文件

在解决方案资源管理器中右键单击文件,确保它的构建操作设置为“c# Compiler”

解决方案资源管理器—>右键单击文件—>“属性”—>构建动作=“c#编译器”

我把“调试”改为“释放”,它又工作了(任何CPU)。