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

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

问题描述

我有一个带有两个xunit测试项目的.net核心解决方案。该版本运行在Azure DevOps管道上,我想将测试范围发布到SonarQube(社区)服务器。



我基本上遵循以下博客帖子,并且几乎可以正常运行,问题是我只看到了上一个测试项目的覆盖范围,而不是全部看到了。



我可能是错误,但来自此问题,我猜想我需要先合并* .coveragexml文件发送到SonarQube。



我已经看到您可以将Coverage文件与Coverlet之类的工具合并,但是当我尝试( ))(例如找不到文件xunit.runner.reporters.netcoreapp10_101ce3bf-0896-4b2a-9f9e-67d8c0b742e6.pdb) p>

在碰到这个兔子洞之前,我更想知道我是否真的需要合并我的.coveragexml文件...如果可以的话,我可以使用常规工具来做到吗?我需要其他人,例如Coverlet ...



干杯

解决方案

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

 信息:传感器C#测试覆盖率报告导入[csharp] 
INFO:解析Visual Studio覆盖率XML报告[...]
INFO:将此代码覆盖率报告添加到缓存中[...]
INFO:解析Visual Studio覆盖率XML报告[...]
信息:将此代码覆盖率报告添加到缓存[...]

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



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

 < DebugType>完整< / DebugType> 

在一个项目中。奇怪的是,其他项目报告的某些代码覆盖率未在.csproj中设置此属性,因此我认为我不需要它。



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


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.

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

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)

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...

Cheers

解决方案

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 [...]

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

The reported coverage was false because I needed to add a

<DebugType>Full</DebugType>

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.

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

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

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