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

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

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

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

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


当前回答

我解决的问题与这里的任何解决方案都完全不同:

我的每个测试都调用了一个函数,这个函数反过来调用自己,这意味着它不会终止:

public GoogleIntent CreateIntent(BotPath botpath)
{
    return CreateIntent(botpath);
}

其他回答

在我的情况下需要安装Microsoft.NET.Test.Sdk

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的引用:

在我的例子中,我已经安装了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

Clean-Rebuild解决方案对我很有效。

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

MSTest。TestAdapter MSTest。TestFramework

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