gpt4 book ai didi

c# - 除非删除 App.Config,否则不会发现 Visual Studio 2017 单元测试

转载 作者:行者123 更新时间:2023-11-30 23:08:41 32 4
gpt4 key购买 nike

这是最奇怪的事情。我有一个包含多个类库项目(所有 .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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com