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

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

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

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

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


当前回答

对我来说,问题是我的ClassInit()方法没有正确的签名。

MSTest类初始化和清理属性

特别要注意ClassInit()方法上的[ClassInitialize]属性。

工作原理:

[ClassInitialize]
public static void ClassInit(TestContext context)
{

}

没有工作:

[ClassInitialize]
public void ClassInit(TestContext context)
{

}

or

[ClassInitialize]
public static void ClassInit()
{

}

or

[ClassInitialize]
public void ClassInit()
{

}

其他回答

我在VS 2017也遇到了同样的问题。在我的例子中,它通过重新启动VS来解决。

我使用。net 4.7的VS2019。我安装了NUnit扩展v3,并将测试设置改为使用X64。我的单元测试项目是任何CPU(如果我把它改成x64就可以工作)。现在我可以调试我的代码了。

对我来说,重新启动VS2017不起作用。我必须清理sln,然后找到一个没有运行测试的文件,只运行该文件。在那之后,我确实运行了所有,它又正常工作了。

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

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.