从 Visual Studio 2015 中的代码覆盖率中排除自动属性 [英] Exclude auto properties from Code Coverage in Visual Studio 2015

查看:39
本文介绍了从 Visual Studio 2015 中的代码覆盖率中排除自动属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将一堆项目升级到了 VS2015/C#6.

I just upgraded a bunch of projects to VS2015/C#6.

现在 MSTest 的代码覆盖率分析报告说单元测试未涵盖某些自动属性.在 Visual Studio 2013 中并非如此,我怀疑这可能与 C#6 中的新自动属性功能有关.

Now MSTest's Code Coverage analysis is reporting that some auto properties aren't covered by unit tests. This wasn't the case in Visual Studio 2013, and I suspect it may be something to do with the new autoproperty features in C#6.

处理由此产生的所有误报反而违背了代码覆盖率工具的目的,因为它实际上无法识别缺乏测试覆盖率的实际代码.我们不想为我们所有的 DTO 编写单元测试,而且我真的不想在整个项目中使用 ExcludeFromCodeCoverage 注释每个自动属性.

Dealing with all the false-positives this generates rather defeats the purpose of the Code Coverage tool as it makes it practically impossible to identify actual code lacking test coverage. We don't want to write unit tests for all our DTOs, and I'd really rather not have to go through the project annotating every single auto-property with ExcludeFromCodeCoverage.

我在 https://github.com/iaingalloway/VisualStudioCodeCoverageIssue

  • 在 Visual Studio 2013 Premium 或 Ultimate 中打开 VisualStudio2013.sln.
  • 点击测试 -> 分析代码覆盖率 -> 所有测试.
  • 观察代码覆盖率结果"窗口报告 0 块未覆盖".
  • 在 Visual Studio 2015 Enterprise 中打开 VisualStudio2015.sln.
  • 点击测试 -> 分析代码覆盖率 -> 所有测试.
  • 观察代码覆盖率结果"窗口报告 1 块未覆盖"(ExampleDto.Value 的 getter)

是否可以像 Visual Studio 2013 一样配置 Visual Studio 2015 中的内置代码覆盖率工具来忽略自动属性?

推荐答案

作为一种解决方法,您可以将以下内容添加到 .runsettings 文件中:-

As a workaround, you can add the following to your .runsettings file:-

<RunSettings>
  <DataCollectionRunSettings>
    <DataCollector ...>
      <Configuration>
        <CodeCoverage>
          <Functions>
            <Exclude>
              <Function>.*get_.*</Function>
              <Function>.*set_.*</Function>
            </Exclude>
          ...

这不是一个很好的解决方法,但只要您不使用名称中带有get_"或set_"的任何函数,它就会为您提供所需的行为.

It's not a great workaround, but as long as you aren't using any functions with "get_" or "set_" in the names it should get you the behaviour you need.

这篇关于从 Visual Studio 2015 中的代码覆盖率中排除自动属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆