我想在本地 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>"
The dotnet test
命令生成的覆盖率报告为coverage.cobertura.xml
文件在<TestProjectDir>.TestResults\<some-guid>\
folder.
在日志中我可以看到以下警告: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 https://community.sonarsource.com/t/coverage-troubleshooting-guide-for-net-code-coverage-import/37151从警告消息中,我只能看到Visual Studio 代码覆盖率, dotCover and 开放式封面/封面都支持。据我所知,从他们的GitHub 页面 https://github.com/coverlet-coverage/coverlet, is 开放式封面/封面是“XPlat 代码覆盖率”。
在我的测试项目中coverlet.collector
NuGet 包 v 3.0.3 已安装。
我缺少什么?
我发现这个相关问题:SonarQube:无法导入测试覆盖率 https://stackoverflow.com/questions/64914897/sonarqube-unable-to-import-test-coverage但这对我没有帮助,因为我无法使用dotCover.