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

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

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

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

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


当前回答

请确保您选择了正确的项目类型。在我的例子中,我选择了“单元测试项目”,我应该有“xUnit测试项目”。

其他回答

将测试项目升级到最新的目标框架版本。

我使用的是Visual studio 2019,目标框架4.5的支持在2016年结束,跳转到4.7解决了我的问题。

在我的情况下,我有一个async void方法,我用async任务替换,所以测试运行如我所料:

    [TestMethod]
    public async  void SendTest(){}

替换为:

    [TestMethod]
    public async  Task SendTest(){}

如果你的项目不全是AnyCpu,那么你可能还想检查以下2个设置是否匹配:

[右键单击测试项目]->属性->构建->平台目标-例如x64 [主菜单]-> Test -> Test Settings -> Default Processor Architecture -> X64 .

我发现,当这些不匹配时,我的测试项目将无声地失败运行。

这里是测试项目没有被标记为建造:

Build ->配置管理器…->检查你的测试项目的构建

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.