在处理由 Visual Studio 的 MSTest 生成的 .coveragexml 文件时,Sonar Runner 出错 [英] Sonar Runner errors out during processing of .coveragexml file produced from Visual Studio's MSTest

查看:20
本文介绍了在处理由 Visual Studio 的 MSTest 生成的 .coveragexml 文件时,Sonar Runner 出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试处理从命令行使用 MSTest 后获得的 .coveragexml 文件(在转换 .coverage 文件之后),但 Sonar Runner 在尝试解析文件时一直失败.错误包括解析错误,例如意外的?"以及无法在文件中找到标签.

I am trying to process my .coveragexml file (after converting the .coverage file) that I get after using MSTest from the command line but Sonar Runner keeps failing as it tries to parse the file. The errors consist of parsing errors such as an unexpected '?' as well as not being able to find the tag in the file.

我尝试了几种获取 .coveragexml 文件的方法:从命令行使用vsinstr -coverage ..."和start vsperfmon -coverage ..."命令(然后运行 ​​MSTest),更改.testrunco​​nfig 文件并指示我想要覆盖哪些 dll,并尝试使用CodeCoverage.exe collect ...".前两个使我成功地获取了代码覆盖率数据,但我在获取CodeCoverage.exe collect ..."以收集结果时遇到了问题.尽管我可以从前两个收集代码覆盖率结果,但 .coveragexml 文件是生成的格式似乎不是 SonarQube 接受的正确格式,即使他们在 VB.NET 插件网页上表明他们支持 MSTest 和 VSTest XML 代码覆盖文件.我已经尝试使用 VSTest 并且可以让 Sonarqube 接受我的 .coveragexml 文件而不会出现任何错误.问题是我实习的公司使用 MSTest 来运行所有他们的单元测试,所以我需要使用 MSTest 获取 .coveragexml 数据.

I have tried a few ways to get the .coveragexml file: using the "vsinstr -coverage ..." and "start vsperfmon -coverage ..." commands (then running MSTest) from the command line, changing the .testrunconfig file and indicating which dlls I want to get coverage for, and tried using "CodeCoverage.exe collect ...". The first two have given me success on getting code coverage data, but I have had issues getting "CodeCoverage.exe collect ..." to collect results. Even though I can get collect code coverage results from the first two, the .coveragexml file that is produced does not seem to be in the right format that SonarQube accepts, even though they indicate on their VB.NET plugin webpage that they support MSTest and VSTest XML code coverage files. I have tried using VSTest and can get my .coveragexml files to be accepted by Sonarqube without any errors just fine. The problem is that the company I am interning for uses MSTest to run all of their unit tests, so I need to get .coveragexml data from using MSTest.

我注意到的另一件事是,当我尝试在 Visual Studio 中将 .coverage 文件导出为 .coveragexml 时(对于 MSTest 或 VSTest),它会生成 Sonarqube 的 .coveragexml 格式不接受(由于我上面提到的错误,它只是出错了).当我使用CodeCoverage.exe 分析 ..."命令从 VSTest 转换 .coverage 文件时,它会生成一个Sonarqube 接受的 .coveragexml 格式,因为我没有收到任何错误,并且可以在仪表板上看到我的代码覆盖率结果.现在,当我尝试使用CodeCoverage.exe 分析 ..."命令进行转换时来自 MSTest 的 .coverage 文件,没有任何反应.不会生成 .coveragexml 文件,也不会给出任何错误或任何形式的反馈.我还尝试编写一个 C# 方法来转换 .coverage使用 Microsoft.VisualStudio.Coverage.Analysis 将文件转换为 .coveragexml 文件.但它会生成相同格式的 .coveragexml 文件,就像我从 Visual Studio 中导出它一样.

Another thing I noticed was that when I try to export the .coverage file as a .coveragexml within Visual Studio (for both MSTest or VSTest), it produces a .coveragexml format that Sonarqube doesn't accept (it just errors out due to the errors I mentioned above). When I use the "CodeCoverage.exe analyze ..." command to convert the .coverage file from VSTest, it produces a .coveragexml format that Sonarqube accepts as I receive no errors and can see my code coverage results on the dashboard. Now when I try to use "CodeCoverage.exe analyze ..." command to convert the .coverage file from MSTest, nothing happens. No .coveragexml file is produced and no errors or any sort of feedback is given. I have also tried writing a C# method to convert the .coverage file to a .coveragexml file using Microsoft.VisualStudio.Coverage.Analysis. But it produces the same format .coveragexml file as if I were exporting it from Visual Studio.

其他可能有助于了解的事情:

Other things that might be helpful to know:

  • 我正在对 VB.NET 代码进行分析.
  • 我正在使用 Sonarqube 的 VB.NET 插件的 2.2 版.
  • 我使用的是 4.3.2 版的 Sonarqube 和 2.4 版的 SonarQube Runner.
  • 我正在使用 Visual Studio 2013 Premium.

(SonarQube 出错)从 Visual Studio 导出后的 .coveragexml 文件格式如下:

(SonarQube errors out) The format of the .coveragexml file after exporting it from Visual Studio is like this:

<CoverageDSPriv>
<xs:schema ...>
  ...
</xs:schema>
<Module>
  <ModuleName>...</ModuleName>
  <ImageSize>...</ImageSize>
  ...
  <NameSpaceTable>
    <BlocksCovered>...</BlocksCovered>
    ...

(SonarQube 接受)使用CodeCoverage.exe 分析..."后的.coveragexml 文件格式(仅适用于VSTest 的.coverage 文件)

(SonarQube accepts) The format of the .coveragexml file after using "CodeCoverage.exe analyze ..." (only works with VSTest's .coverage file)

<?xml version="1.0" encoding="UTF-8" ?>
<results>
  <modules>
    <module name="..." path="..." id="..." block_coverage="..." line_coverage="..."  blocks_covered="..." ... >
      <functions>
        <function id="..." token="..." name="..." type_name="..." block_coverage="..." >
        ...

看起来这个数据有两种完全不同的模式,SonarQube 只接受其中一种,是这样吗?还有其他方法可以将 .coverage 数据转换为 SonarQube 接受的数据吗?

It looks like there are two completely different schemas for this data and SonarQube is only accepting one of them, is that the case? Is there another way to convert the .coverage data to the one that SonarQube accepts?

推荐答案

我想你已经完美地描述了这种情况:确实有两个完全不同的代码覆盖率报告,它们都使用 *.coveragexml 扩展名.

I think you've perfectly described the situation: There indeed are two totally different code coverage reports, which both uses the *.coveragexml extension.

C# 和 VB.NET 插件目前仅支持其中一种格式,并且存在添加对另一种格式的支持的票证:https://jira.codehaus.org/browse/SONARNTEST-3

The C# and VB.NET plugin only support one of those formats at the moment, and a ticket exists to add the support for the other: https://jira.codehaus.org/browse/SONARNTEST-3

这篇关于在处理由 Visual Studio 的 MSTest 生成的 .coveragexml 文件时,Sonar Runner 出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆