SonarQube:无法导入测试覆盖率 [英] SonarQube: Unable to import test coverage

查看:53
本文介绍了SonarQube:无法导入测试覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SonarQube 安装,并且正在针对具有多个 xUnit 项目的 .Net 核心应用程序运行它.SonarQube 发现了错误并且闻起来很好,但和很多人一样,我无法完成代码覆盖.

I have a SonarQube installation and am running it against a .Net core application with multiple xUnit projects. The SonarQube picks up the bugs and smells fine but like so many people, I can't get the code coverage to complete.

目前,我正在使用以下命令生成 cobertura 覆盖 XML 文件:

At present, I am generating cobertura coverage XML files using the following command:

dotnet test --collect:"XPlat Code Coverage"

然后我将这些文件从每个测试项目复制到一个集中目录,并使用以下命令运行/导入文件:

I then copy these to a centralized directory from each of the test projects and use the following command to run/import the files:

dotnet SonarScanner begin /k:"my-project" /d:sonar.cs.vscoveragexml.reportsPaths=".TestResults*.xml"
dotnet build
dotnet SonarScanner end

根据日志,文件被找到但没有被摄取.

According to the logs, the files are found but are not ingested.

信息:解析 Visual Studio 覆盖率 XML 报告C:...TestResults5.coverage.cobertura.xml 警告:无法导入覆盖率报告 '..TestResults5.coverage.cobertura.xml' 因为'缺少根元素C:...TestResults5.coverage.cobertura.xml 第 2 行'

INFO: Parsing the Visual Studio coverage XML report C:...TestResults5.coverage.cobertura.xml WARN: Could not import coverage report '..TestResults5.coverage.cobertura.xml' because 'Missing root element in C:...TestResults5.coverage.cobertura.xml at line 2'

我已经确认这些文件包含看起来正确的有效 XML,但我什至不确定 SonarQube 是否应该接受 cobertura 报告.

I've confirmed that the files contain valid XML that looks to be correct, but I'm not even sure that SonarQube is supposed to accept cobertura reports.

  • 在尝试将 xUnit 覆盖率报告输入 SonarQube 时,我的方法是否与其他人采用的方法相同?
  • 有更好的方法吗?如果更容易,我很乐意使用 OpenCover 或类似工具.

推荐答案

如果将来有人遇到这种情况,我放弃了尝试使用 VS 中的内置覆盖率并使用 DotCover.更简单的设置,现在似乎可以在一定程度上工作.

In case anyone comes across this in the future, I gave up trying to use the built in coverage in VS and used DotCover. Bit of an easier setup and now seem to have it working to a degree.

  • 下载/提取 dotCover 并将文件夹添加到 Path
  • dotCover.exe --output=AppCoverageReport.html --reportType=HTML dotnet -- 测试
  • dotnet SonarScanner begin/k:我的项目"/d:sonar.cs.dotcover.reportsPaths=AppCoverageReport.html
  • dotnet 构建
  • dotnet SonarScanner 端

仍然存在一个问题,即测试覆盖率收集似乎过多,结果导致错误.正在调查但与此问题无关.

Still having an issue where the test coverage gathering seems to be pulling in too much and as a result is causing an error. Investigating but not related to this question.

这篇关于SonarQube:无法导入测试覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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