代码覆盖率-Azure Qube
我使用Azure管道来运行单元测试和SonarQube集成。当我使用cobertura进行单元测试时,我无法获得传递到SonarQube的代码覆盖率结果,尽管我可以在管道日志中看到结果。然而,当我使用OpenCover时,同样的事情也会发生 我也在管道日志中看到了这个警告,尽管我不确定这是否相关:“缺少以下文件的责任信息” 管道目前看起来如下所示代码覆盖率-Azure Qube,azure,azure-devops,sonarqube,azure-pipelines,sonarscanner,Azure,Azure Devops,Sonarqube,Azure Pipelines,Sonarscanner,我使用Azure管道来运行单元测试和SonarQube集成。当我使用cobertura进行单元测试时,我无法获得传递到SonarQube的代码覆盖率结果,尽管我可以在管道日志中看到结果。然而,当我使用OpenCover时,同样的事情也会发生 我也在管道日志中看到了这个警告,尽管我不确定这是否相关:“缺少以下文件的责任信息” 管道目前看起来如下所示 - task: DotNetCoreCLI@2 inputs: command: ‘test’ projects:
- task: DotNetCoreCLI@2
inputs:
command: ‘test’
projects: |
<test-proj>
arguments: ‘/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura’
displayName: ‘Run Tests’
- task: SonarQubePrepare@4
inputs:
SonarQube: <Service-Endpoint>
scannerMode: ‘MSBuild’
projectKey: ‘test:service’
projectName: ‘test:service’
extraproperties: |
sonar.flex.cobertura.reportPaths=$(Build.SourcesDirectory)/**/coverage.cobertura.xml
- task: DotNetCoreCLI@2
<Running DotNet build>
- task: SonarAnalyze@4
-任务:DotNetCoreCLI@2
投入:
命令:“测试”
项目:|
参数:'/p:CollectCoverage=true/p:CoverletOutputFormat=cobertura'
displayName:“运行测试”
-任务:SonarQubePrepare@4
投入:
索纳库贝:
扫描模式:“MSBuild”
projectKey:“测试:服务”
projectName:“测试:服务”
外部属性:|
sonar.flex.cobertura.reportpath=$(Build.SourcesDirectory)/**/coverage.cobertura.xml
-任务:DotNetCoreCLI@2
-任务:SonarAnalyze@4
在运行DotNet测试阶段时,将在此路径中获得测试结果-
E:\agent-5\2\s\test\ApiTest\coverage.cobertura.xml
任何建议都将不胜感激。您的步骤顺序需要从
测试->准备测试->构建->分析更改为准备测试->构建->测试->分析,如下所示:
-任务:SonarQubePrepare@4
投入:
索纳库贝:
扫描模式:“MSBuild”
projectKey:“测试:服务”
projectName:“测试:服务”
外部属性:|
sonar.flex.cobertura.reportpath=$(Build.SourcesDirectory)/**/coverage.cobertura.xml
-任务:DotNetCoreCLI@2
-任务:DotNetCoreCLI@2
投入:
命令:“测试”
项目:|
参数:'/p:CollectCoverage=true/p:CoverletOutputFormat=cobertura'
displayName:“运行测试”
-任务:SonarAnalyze@4
更新:显然,默认情况下,SonarQube不允许发布Cobertura结果文件(或者至少我无法让它运行)
使用了一种变通方法-我必须将OpenCover测试结果文件传递给SonarQube。为了将结果推送到Azure Devops上,我必须使用reportgenerator工具将结果转换为Cobertura,然后再将结果传递给Azure Devops。Azure管道上的代码覆盖率报告很好。但是,当使用cobertura时,它们不会传递给SonarQube。一旦您准备好SonarQube任务,它将开始监视生成的日志并开始将它们发送给SonarQube,这也将提高代码覆盖率,因此任务的顺序很重要。您的问题进展如何?下面的回答有帮助吗?你可以,这对阅读此帖子的其他社区成员是有益的。