将多个 .NET Core 项目的测试覆盖范围从 Azure DevOps 发布到 SonarQube 服务器 [英] Publish test coverage of multiple .NET Core Projects from Azure DevOps to SonarQube server

查看:22
本文介绍了将多个 .NET Core 项目的测试覆盖范围从 Azure DevOps 发布到 SonarQube 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含两个 xunit 测试项目的 .net 核心解决方案.构建在 Azure DevOps 管道上运行,我想将测试覆盖范围发布到 SonarQube(社区)服务器.

I have a .net core solution with two xunit test projects. The build runs on Azure DevOps pipeline and I want to publish the test coverage to a SonarQube (Community) server.

我基本上遵循了这个博客文章 并且它几乎可以工作,问题是我只看到最后一个测试项目的覆盖率,而不是两者.

I have basically followed this blog post and it is almost working, the issue is that I only see the coverage of the last test project, not both of them.

我可能错了但是从这个问题我猜我需要合并在发送到 SonarQube 之前我的 *.coveragexml 文件.

I may be wrong but from this issue I guessed that I need to merge my *.coveragexml files before sending to SonarQube.

我已经看到您可以使用 Coverlet 等工具合并覆盖文件,但是当我尝试时 (来自此帮助页面)我遇到了一些错误(例如找不到文件 xunit.runner.reporters.netcoreapp10_101ce3bf-0896-4b2a-9f9e-67d8c0b742e6.pdb)

I have seen that you can merge coverage files with tools like Coverlet but when I tried (from this help page) I got some errors (like Could not find file xunit.runner.reporters.netcoreapp10_101ce3bf-0896-4b2a-9f9e-67d8c0b742e6.pdb)

在遇到这个兔子洞之前,我更想知道我是否真的需要合并我的 .coveragexml 文件......如果是这样,我可以使用常规工具来完成还是需要其他工具,例如 Coverlet......

Before running into this rabbit hole I would prefer to know if I really need to merge my .coveragexml files... and if so can I do it with the regular tools or do I need others like Coverlet...

干杯

推荐答案

我终于找到了问题所在.您不需要合并 .coveragexml 文件,SonarScanner.MSBuild.exe 的最新版本实际上会找到所有 .coveragexml 文件.我更仔细地查看日志,发现多行如下:

I finally found the issue. You don't need to merge the .coveragexml files, the last version of the SonarScanner.MSBuild.exe actually finds all the .coveragexml files. I looked more closely in the logs and found multiple lines like these:

INFO: Sensor C# Tests Coverage Report Import [csharp]
INFO: Parsing the Visual Studio coverage XML report [...]
INFO: Adding this code coverage report to the cache [...]
INFO: Parsing the Visual Studio coverage XML report [...]
INFO: Adding this code coverage report to the cache [...]

因此找到了 .coveragexml 文件并将其发布到声纳.

So the .coveragexml files were found and published to sonar.

报告的报道是错误的,因为我需要添加一个

The reported coverage was false because I needed to add a

<DebugType>Full</DebugType>

在一个项目中.奇怪的是,其他项目报告了一些代码覆盖率,但没有在 .csproj 中设置此属性,所以我认为我不需要它.

In a project. The odd thing is that the other projects reported some code coverage without this property set in the .csproj so I thought I didn't need it.

因此,如果报告的覆盖范围似乎是错误的,请尝试在 csproj 中添加此属性.

So if the reported coverage seems false, try adding this property in the csproj.

这篇关于将多个 .NET Core 项目的测试覆盖范围从 Azure DevOps 发布到 SonarQube 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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