c# - 如何让 VS 忽略 Test dll 的代码覆盖率

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

目前,当我运行代码覆盖率分析时,报告的覆盖率是 90%。关键是另外10%是实际测试的代码!

如何让 VS 忽略该测试代码,只考虑实际代码?

最佳答案

您可以在您的项目中添加一个运行设置文件。

在该文件中,您可以提及需要从代码覆盖范围中排除的 DLL 名称:

<ModulePaths>
  <Include>
    <!-- Include all loaded .dll assemblies (but not .exe assemblies): -->
    <ModulePath>.*\.dll$</ModulePath>
  </Include>
  <Exclude>
    <!-- But exclude some assemblies: -->
    <ModulePath>.*\\Fabrikam\.MyTests1\.dll$</ModulePath>
    <!-- Exclude all file paths that contain "Temp": -->
    <ModulePath>.*Temp.*</ModulePath>
  </Exclude>
</ModulePaths>

This pageThis page应该为您提供有关如何为单元测试添加和配置 runsettings 文件的更多详细信息。

希望对您有所帮助。

关于c# - 如何让 VS 忽略 Test dll 的代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54402661/

相关文章:

c# - SQL 和 ASP.NET 从物化 'System.Int64' 类型到 'System.Int32' 类型的指定转换无效

c# - 将用户限制在 OpenFileDialog 中的特定目录

c++ - 链表显示乱码

c# - 是否有可能 "spoof"网络摄像头提要?

.net - 为什么接口(interface)契约(Contract)不适用于装配外部?

django - 如何在 django-rest-framework 中单元测试权限?

java - 使用模拟对象进行 junit 测试 : stub inner function calls

c# - 为 ApplicationUser.cs 添加 Controller ? MVC核心

xaml - CustomButton_123509716 targetType 与元素的类型不匹配 CustomButton_096728

c# - 完成事务后更改 TransactionScope IsolationLevel