我对 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:
运行 MSBuild.SonarQube.Runner.exe 开始命令,使用
/d:propertyKey=path
语法指定代码覆盖率报告可用的绝对路径(“propertyKey”取决于代码覆盖工具)使用 MSBuild 构建您的项目
运行您的代码覆盖工具,指示它在之前指定的相同位置为 MSBuild SonarQube Runner 生成报告
运行 MSBuild.SonarQube.Runner.exe 结束命令
关于c# - 代码覆盖 xml 生成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36641673/