小编Chr*_*aro的帖子

如何使用Visual Studio 2012中的runsettings文件从代码覆盖中排除服务引用?

我正在使用自定义runsettings文件来控制检查代码覆盖率的项目.我使用了Microsoft提供的默认模板,并且到目前为止能够排除我想要的项目而没有任何问题.我的下一步操作是从代码覆盖中排除在添加服务引用时由Visual Studio创建的自动生成的Web代理类.

这似乎适用于默认的runsettings模板,因为它有一个如下所示的部分:

<Attributes>
    <Exclude>
        <!-- Don’t forget "Attribute" at the end of the name -->
        <Attribute>^System.Diagnostics.DebuggerHiddenAttribute$</Attribute>
        <Attribute>^System.Diagnostics.DebuggerNonUserCodeAttribute$</Attribute>
        <Attribute>^System.Runtime.CompilerServices.CompilerGeneratedAttribute$</Attribute>
        <Attribute>^System.CodeDom.Compiler.GeneratedCodeAttribute$</Attribute>
        <Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
    </Exclude>
</Attributes>
Run Code Online (Sandbox Code Playgroud)

添加服务引用时创建的所有类都使用GeneratedCodeAttribute进行修饰,因此应排除它们.但是,当我运行代码覆盖时,它们不会被忽略,因此代码覆盖率会报告大量未覆盖的代码.我已经多次尝试使用正则表达式,试图让它正确地选择属性而无济于事.

我很感激有关如何使用的建议: - 让这个属性排除工作 - 一个不需要我排除整个项目或使runsettings文件非泛型的替代方法(我们想重新使用这个基本文件在没有特定编辑的所有项目中)

仅供参考 - 虽然我了解其他代码覆盖工具,但我的目标是使Visual Studio工作,因此在这种情况下,关于切换到其他工具的建议对我没有帮助.

unit-testing mstest code-coverage visual-studio-2012 visual-studio-test-runner

12
推荐指数
3
解决办法
9742
查看次数