BuildQualityChecks 任务不考虑所有已发布的测试覆盖率报告

问题描述 投票:0回答:1

我有 3 个单元测试项目,用于解决方案中的 3 个不同项目。

  • API
  • 服务
  • 数据

当我运行构建管道时,这些单元测试项目会生成 3 个结果,而当代码覆盖率任务运行时,它只选择一个报告。

如何将所有报告合并为一个并进行验证?

在管道结果中,如果我转到“代码覆盖率”选项卡,它具有正确的总行覆盖率值。 output published

但是代码覆盖率工具显示的数字较少 output of the pipeline

管道步骤如下

- task: DotNetCoreCLI@2
  displayName: dotnet test $(buildConfiguration)
  inputs:
    command: test
    publishTestResults: true
    projects: '$(unitTestsDirs)/**/*.csproj'
    arguments: '--configuration $(buildConfiguration) --no-build --collect:"XPlat Code Coverage" --settings "./coverage.runsettings" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura'
    
- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage report'
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
    
- task: BuildQualityChecks@9
  displayName: 'Check build quality'
  inputs:
    checkCoverage: true
    coverageFailOption: fixed
    coverageType: lines
    coverageThreshold: $(CoverageThreashold)
    buildPlatform: $(BuildPlatform)

测试输出的位如下

Results File: /azp/_work/_temp/_rancher-ubuntu-on-prem-agents-nhpsb_2024-11-18_15_05_23.trx
Attachments:
/azp/_work/_temp/d0caa73f-caee-48d1-b626-f49093a0fb14/_rancher-ubuntu-on-prem-agents-nhpsb_2024-11-18.15_05_23.cobertura.xml
/azp/_work/_temp/d0caa73f-caee-48d1-b626-f49093a0fb14/coverage.cobertura.xml

Results File: /azp/_work/_temp/_rancher-ubuntu-on-prem-agents-nhpsb_2024-11-18_15_05_30.trx
Attachments:
/azp/_work/_temp/1c8c6bf9-96be-405d-b0b5-b852eb474a1b/_rancher-ubuntu-on-prem-agents-nhpsb_2024-11-18.15_05_31.cobertura.xml
/azp/_work/_temp/1c8c6bf9-96be-405d-b0b5-b852eb474a1b/coverage.cobertura.xml

Results File: /azp/_work/_temp/_rancher-ubuntu-on-prem-agents-nhpsb_2024-11-18_15_05_35.trx
Attachments:
/azp/_work/_temp/6bb84b94-f726-44b0-94ce-3047f7af5c91/_rancher-ubuntu-on-prem-agents-nhpsb_2024-11-18.15_05_36.cobertura.xml
/azp/_work/_temp/6bb84b94-f726-44b0-94ce-3047f7af5c91/coverage.cobertura.xml

Async Command Start: Publish test results
Publishing test results to test run '911742'.
TestResults To Publish 55, Test run id:911742
Test results publishing 55, remaining: 0. Test run id: 911742
Publishing test results to test run '911744'.
TestResults To Publish 50, Test run id:911744
Test results publishing 50, remaining: 0. Test run id: 911744
Publishing test results to test run '911743'.
TestResults To Publish 71, Test run id:911743
Test results publishing 71, remaining: 0. Test run id: 911743
Published Test Run : https://dev.azure.com/xxxxx/Runs?runId=911742&_a=runCharts
Published Test Run : https://dev.azure.com/xxxxx/Runs?runId=911744&_a=runCharts
Published Test Run : https://dev.azure.com/xxxxx/Runs?runId=911743&_a=runCharts

发布步骤有此警告:

##[警告]发现多个文件或目录匹配。使用第一个匹配项:/azp/_work/_temp/1c8c6bf9-96be-405d-b0b5-b852eb474a1b/coverage.cobertura.xml

因此,构建质量检查的覆盖行数量非常少

unit-testing azure-devops azure-pipelines code-coverage
1个回答
0
投票

您可以使用扩展ReportGenerator来合并代码覆盖率报告。

- task: reportgenerator@5
  inputs:
    reports: '**/coverage.cobertura.xml'
    targetdir: 'coveragereport'
    publishCodeCoverageResults: true
- task: BuildQualityChecks@9
  displayName: 'Check build quality'
  inputs:
    checkCoverage: true
    coverageFailOption: 'fixed'
    coverageType: 'lines'
    coverageThreshold: '60'

在 dotnet 测试后添加

reportgenerator@5
任务。您可以在此任务中将
publishCodeCoverageResults
设置为
true
,这样就不需要添加
PublishCodeCoverageResults@1
任务。

© www.soinside.com 2019 - 2024. All rights reserved.