这是最奇怪的事情。我有一个包含多个类库项目(所有 .Net Framework 4.7)和多个单元测试项目来测试这些类库的解决方案。我偶尔会升级 NuGet 包以使其保持最新状态,其中一些升级会将 app.config 文件引入到测试项目中。引入 app.config 后,Visual Studio 就不再发现测试,因此每次构建后不再运行它们。考虑到失败的测试是纠正代码的触发器,这创建了一个场景,我们将引入单元测试失败的代码,但因为我们非常依赖自动化,所以我们假设它成功了。
总结: - app.config的存在使得VS2017无法发现包含app.config的项目中的测试,即使app.config完全为空。仅删除配置文件将使 VS2017 重新发现测试 - 解决方案中的所有内容都针对 .Net Framework 4.7 - 所有 Nuget 包均已更新,包括 MsTest 适配器和 TestFramework - app.config 文件仅填充程序集绑定(bind)条目,例如:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
最佳答案
找到了肇事者,我想我会分享以防其他人遇到这种情况。将 System.Runtime NuGet 包添加到我的测试项目后,VS2017 发现了这些测试。
关于c# - 除非删除 App.Config,否则不会发现 Visual Studio 2017 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46339185/