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

标签 c# unit-testing visual-studio-2017

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

相关文章:

hibernate - 使用 spring 对 hibernate daos 进行单元测试

c# - 如何从 Visual studio 2017 预览版 2 指定 Azure Function 的输出绑定(bind)?

c# - 在 C# 中使用 Selenium,无需在 Visual Studio 2013 中打开浏览器

c# - 在C#中从和弦中提取音符

unit-testing - SenTestKit : cleaning up after ALL tests have run?

Python "in"不检查类型?

c# - 如何从 Visual Studio Team Services 运行 ASP.NET Core Entity Framework 迁移

c++ - 调试显示不正确值的 64 位 DLL 检查器

c# - C#显示线程无效的跨线程访问问题

c# - Linq to Entities 中的规范函数不起作用