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

查看:151
本文介绍了在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的获取器)

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

推荐答案

作为一种解决方法,您可以将以下内容添加到您的.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天全站免登陆