将多个 .NET Core 项目的测试覆盖率从 Azure DevOps 发布到 SonarQube 服务器

编程入门 行业动态 更新时间:2024-10-28 05:13:32
本文介绍了将多个 .NET Core 项目的测试覆盖率从 Azure DevOps 发布到 SonarQube 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I have a 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.

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

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.

我可能错了,但是从 this issue 我猜我需要合并我的 *.coveragexml 文件在发送到 SonarQube 之前.

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.reporterscoreapp10_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.reporterscoreapp10_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 服务器

本文发布于:2023-11-14 18:55:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588262.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   覆盖率   服务器   测试   项目

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!