简体   繁体   English

未找到 SonarQube 的 Azure 管道中的报告代码覆盖率

[英]Report Code Coverage in Azure Pipeline for SonarQube not found

I'm struggling to generate a code coverage repot in Azure DevOps Pipeline for SonarQube. I need this Code Coverage report so SonarQube will be aware about total code coveraged in the Unit Tests.我正在努力为 SonarQube 在 Azure DevOps 管道中生成代码覆盖率报告。我需要此代码覆盖率报告,以便 SonarQube 了解单元测试中覆盖的总代码。

I am getting this error message in the step to get the report created during the Unit tests:我在获取单元测试期间创建的报告的步骤中收到此错误消息:

2022-01-20T15:56:14.9054419Z ========================== Starting Command Output ===========================
2022-01-20T15:56:14.9976248Z ##[command]"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\Agents\xx\_work\_temp\cd6ffda1-xx-799dfd098791.ps1'"
2022-01-20T15:56:18.7184739Z You can invoke the tool using the following command: reportgenerator
2022-01-20T15:56:18.7185160Z Tool 'dotnet-reportgenerator-globaltool' (version '5.0.2') was successfully installed.
2022-01-20T15:56:18.9728580Z 2022-01-20T07:56:18: Arguments
2022-01-20T15:56:18.9729027Z 2022-01-20T07:56:18:  -reports:D:\Agents\xxx\_work\26\s/**/TestResults/coverage.opencover.xml
2022-01-20T15:56:18.9729118Z 2022-01-20T07:56:18:  -targetdir:coverage/Cobertura
2022-01-20T15:56:18.9729175Z 2022-01-20T07:56:18:  -reporttypes:Cobertura;HTMLInline;HTMLChart
2022-01-20T15:56:19.1740700Z 2022-01-20T07:56:19: The report file pattern 'D:\Agents\xxx\_work\26\s/**/TestResults/coverage.opencover.xml' found no matching files.
2022-01-20T15:56:19.1741530Z 2022-01-20T07:56:19: No report files specified.
2022-01-20T15:56:19.8181717Z ##[error]PowerShell exited with code '1'.
2022-01-20T15:56:19.8683861Z ##[section]Finishing: Generate Coverage Report

Steps that I followed to generate the report in Azure Pipeline:我在 Azure 管道中生成报告所遵循的步骤:

1- After a "do.net build" step I included a "do.net test" with the following arguments: 1- 在“do.net 构建”步骤之后,我包含了一个“do.net 测试”,其中包含以下 arguments:

steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
    command: test
    projects: '**/UnitTests.csproj'
    arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput=./TestResults/'
  continueOnError: true

2- After "do.net test" step I included a PowerShell script to get the report generated and Convert this report into Cobertura format for Azure DevOps: 2- 在“do.net 测试”步骤之后,我包含了一个 PowerShell 脚本来生成报告并将此报告转换为 Cobertura 格式以用于 Azure DevOps:

steps:
- powershell: |
   dotnet tool install dotnet-reportgenerator-globaltool --tool-path .
   ./reportgenerator "-reports:$(Build.SourcesDirectory)/**/TestResults/coverage.opencover.xml" "-targetdir:coverage/Cobertura" "-reporttypes:Cobertura;HTMLInline;HTMLChart"
  displayName: 'Generate Coverage Report'

As far as I know after this Powershell step I will have to include 2 more steps to publish the reports into Azure and Sonarqube. However, it looks like I have some issues to find the report generated during the Unit Tests.据我所知,在 Powershell 这一步之后,我将不得不包括另外 2 个步骤,以将报告发布到 Azure 和 Sonarqube。但是,看起来我在查找单元测试期间生成的报告时遇到了一些问题。

Any idea about this?对此有什么想法吗?

Thanks.谢谢。

If you add coverlet coverage nuget package in your test project then you do not need to use opencover intermediate step at all.如果您在测试项目中添加覆盖物覆盖 nuget package,那么您根本不需要使用 opencover 中间步骤。 The gives you output in cobertura format, which can be published by code coverage yaml task为您提供 cobertura 格式的 output,可以通过代码覆盖 yaml 任务发布

see here https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#examples请参阅此处https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#examples

and

here https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-code-coverage?tabs=linux这里https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-code-coverage?tabs=linux

If the coverage.opencover.xml file is not being generated, double check if you have a nuget references on your test project to coverlet.msbuild and OpenCover.如果未生成 coverage.opencover.xml 文件,请仔细检查您的测试项目中是否有 nuget 对 coverlet.msbuild 和 OpenCover 的引用。 Probably only coverlet.msbuild is required.可能只需要 coverlet.msbuild。 You should be able to see this in the logs on DevOps eg:您应该能够在 DevOps 的日志中看到这一点,例如:

Calculating coverage result...
  Generating report 'D:\a\1\s\coverage\coverage.opencover.xml'

From my experience, OpenCover played better with SonarQube than Cobertura did.根据我的经验,OpenCover 在 SonarQube 上的表现比 Cobertura 更好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 代码覆盖率 - Azure 管道 SonarQube - Code coverage - Azure Pipelines SonarQube 在管道 Azure 中发布 PHPUnit 代码覆盖结果 - Publish PHPUnit code coverage result in Pipeline Azure 在 azure devops 门户上查看代码覆盖率报告 - view code coverage report on azure devops portal Azure DevOps 构建管道 - 从代码覆盖范围中排除文件夹 - Azure DevOps Build Pipeline - Exclude a Folder from Code Coverage 代码覆盖率和代码行在sonarqube控制台中显示为“-” - Code Coverage and Lines of Code are displayed as '-' in sonarqube console 我们可以使用 sonarqube 从 Terraform 和 azure devops ci/cd 管道扫描(基础设施即代码)IaC 吗? - can we use sonarqube to scan (Infrastructure as code ) IaC from Terraform with azure devops ci/cd pipeline? azure yaml 构建管道的摘要选项卡上显示不正确的代码覆盖率百分比 - Incorrect code coverage percentage show up on the summary tab of the azure yaml build pipeline 如何在 Azure devops 仪表盘中查看 SonarQube 报告 - How to view SonarQube report in Azure devops dashboard Azure管道,上传构建报告 - Azure pipeline, upload build report PHP Core - 在哪里可以找到 Azure 管道中的代码覆盖率报告? - PHP Core - where can I find the code coverage report in azure pipelines?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM