【问题标题】:Wrong codecoverage xml generation错误的代码覆盖 xml 生成
【发布时间】:2016-08-07 02:29:00
【问题描述】:

我对 VisualStudio CodeCoverage 工具有疑问。我在构建服务器上的 Visual Studio 测试任务期间生成代码覆盖文件。比我有 Sonar runner 任务,并且在这些任务中 *.codecoverage 被转换为 *.codecoveragexml。这些会产生错误的 XML。在 XML 中,一个文件中没有引用现有的行。当文件有 10 行时,错误是对第 21 行的引用。 Sonnar 在分析这些文件时遇到了问题并崩溃。

有人知道如何生成正确的 XML 吗?

谢谢

文件内容

using System;
using SomeOtherNamespace;

namespace SomeNamespace
{
  public class OrderChangedEventHandlerArgs : EventArgs
  {
    public OrderInfo Order { get; set; }
  }
}
<function id="64864" token="0x60003c5" name="get_Order()" type_name="OrderChangedEventHandlerArgs" block_coverage="100.00" line_coverage="100.00" blocks_covered="1" blocks_not_covered="0" lines_covered="2" lines_partially_covered="0" lines_not_covered="0">
  <ranges>
    <range source_id="67" covered="yes" start_line="8" start_column="30" end_line="8" end_column="34" />
    <range source_id="67" covered="yes" start_line="8" start_column="35" end_line="8" end_column="39" />
    <range source_id="67" covered="yes" start_line="21" start_column="5" end_line="21" end_column="51" />
  </ranges>
</function>

【问题讨论】:

    标签: c# xml visual-studio-2015 code-coverage tfsbuild


    【解决方案1】:

    查看以下页面上的说明以获取在 SonarQube 中导入的 Visual Studio 代码覆盖率:http://docs.sonarqube.org/x/CoBh

    .NET 代码覆盖率通过 4 个步骤导入 SonarQube:

    1. 运行 MSBuild.SonarQube.Runner.exe begin 命令,使用 /d:propertyKey=path 语法指定代码覆盖率报告可用的绝对路径(“propertyKey”取决于代码覆盖率工具)

    2. 使用 MSBuild 构建项目

    3. 运行代码覆盖率工具,指示它在之前指定给 MSBuild SonarQube Runner 的同一位置生成报告

    4. 运行 MSBuild.SonarQube.Runner.exe 结束命令

    【讨论】:

    • 我知道,但最初它不是由我调用的,而是由 TFS 2015 Update 1 OnPremise 的代理调用的。我将 Sonar 的任务添加到我的两个项目中,效果都很好,但第二次我从 Sonar 运行器那里收到错误,关于处理代码覆盖的行数超过文件的行数。
    【解决方案2】:

    一种解决方案是在文件末尾添加空行并生成文件,只要错误提示。这不是最好的解决方案,但对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-12
      • 2013-05-28
      • 1970-01-01
      • 2014-07-01
      • 1970-01-01
      相关资源
      最近更新 更多