【发布时间】:2021-07-09 05:19:45
【问题描述】:
我想在本地 SonarQube 实例(在 Windows 上)中显示 .NET 5 单元测试的测试覆盖率。
dotnet sonarscanner begin /k:"MyProject" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="<token>" /d:sonar.cs.opencover.reportsPaths="**\TestResults\*\*.xml"
dotnet build
dotnet test --no-build --collect:"XPlat Code Coverage"
dotnet sonarscanner end /d:sonar.login="<token>"
dotnet test 命令在<TestProjectDir>.TestResults\<some-guid>\ 文件夹中将覆盖率报告生成为coverage.cobertura.xml 文件。
在日志中,我可以看到以下警告:
WARN: Could not import coverage report '<MyTestProject>\TestResults\a4af5812-7f80-469b-8876-3ea0c7c4c98d\coverage.cobertura.xml' because 'Missing root element <CoverageSession> in C:\Users\<Path>\TestResults\a4af5812-7f80-469b-8876-3ea0c7c4c98d\coverage.cobertura.xml at line 2'. Troubleshooting guide: https://community.sonarsource.com/t/37151
根据警告消息中的link,我可以看到只有 Visual Studio Code Coverage、dotCover 和 OpenCover/Coverlet支持的。据我从他们的GitHub page 得知,OpenCover/Coverlet 是“XPlat 代码覆盖率”。
在我的测试项目中,安装了coverlet.collector NuGet 包 v 3.0.3。
我错过了什么?
我发现了这个相关问题:SonarQube: Unable to import test coverage 但它对我没有帮助,因为我无法使用 dotCover。
【问题讨论】:
-
Coverlet默认生成cobertura格式的报告(如文件名所示)
标签: c# unit-testing sonarqube code-coverage