c# - 代码覆盖 xml 生成错误

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

我对 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>

最佳答案

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

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

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

  2. 使用 MSBuild 构建您的项目

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

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

关于c# - 代码覆盖 xml 生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36641673/

相关文章:

debugging - 如何在 NCrunch 中调试失败的测试方法

c# - 从 C 移植到 C# 时是否需要 __W64?

java - 如何让 ImageView 缩放以在宽度允许的范围内尽可能多地填充布局

java - ListView 滚动不起作用

java - 强制 jaxb 解码器忽略 html 标签

wpf - 如何正确忽略由 Visual Studio 调试工具为 XAML 创建的窗口

c# - Visual Studio C# 到 MS Access 连接失败

C# 时间(以微秒为单位)

c# - 我如何访问发件人对象中的数据列表

c# - 这个特定的别名 SQL 列是否存在问题?