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

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

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

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

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


当前回答

尝试从测试方法上面删除[Ignore]属性。

其他回答

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通过创建单元测试向导创建了测试类,默认情况下它不会公开。

对我来说,这是由测量代码覆盖率的VS扩展引起的。它不能引用特定程序集,因此不会运行任何测试。使用以下命令行可以很好地运行测试:

dotnet test

要解决这个问题,您可以选择将所有依赖项复制到Test项目调试文件夹中。这可以确保任何程序集都可以解析,因为“未使用的”程序集不会被删除。您可以在测试项目的.csprog文件中添加以下内容:

<PropertyGroup>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

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

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

在我的测试中。csproj文件