unit-testing - 在 azuredevops 管道中发布代码覆盖率结果失败

标签 unit-testing azure-devops azure-pipelines

我的管道中有一个 .netcode 测试命令和一个发布代码覆盖率结果任务。

配置如下:

steps:
- task: DotNetCoreCLI@2
  displayName: 'Test Public API Project '
  inputs:
    command: test
    projects: '**/DWP.CDA.API.Test.csproj'
    arguments: '--output publish_output --configuration $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:Threshold=99 /p:ThresholdStat=total /p:CoverletOutput=$(Build.SourcesDirectory)\TestResults\Coverage\ --collect "Code coverage"'

steps:
- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage'
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(Build.SourcesDirectory)/TestResults/Coverage/*cobertura.xml'
    reportDirectory: '($(Build.SourcesDirectory)/Src/TestResults/Coverage'

但是好像发布结果没有生效,会显示这样的消息
[warning]No code coverage results were found to publish.

最佳答案

您是否也安装并运行了 ReportGenerator 工具以获取正确格式的代码覆盖率报告?您的警告看起来像是构建任务没有在您正在查看的文件夹中找到要发布的 xml 文件。

我过去使用过以下 yaml 来运行和发布代码覆盖率结果。您需要更改它才能找到您的项目,否则它应该可以工作。

- task: DotNetCoreCLI@2
  displayName: 'Install ReportGenerator'
  inputs:
    command: custom
    custom: tool
    arguments: 'install --global dotnet-reportgenerator-globaltool'

- task: DotNetCoreCLI@2
  displayName: 'Run unit tests - $(buildConfiguration)'
  inputs:
    command: 'test'
    arguments: '--no-build --configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/'
    publishTestResults: true
    projects: '**/*.Tests.csproj'

- script: |
    reportgenerator -reports:$(Build.SourcesDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines
  displayName: 'Create code coverage report'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage report'
  inputs:
    codeCoverageTool: 'cobertura'
    summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'

关于unit-testing - 在 azuredevops 管道中发布代码覆盖率结果失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60275777/

相关文章:

java - 有没有办法合法地转换 Mockito 模拟对象?

javascript - 在 Jest 中使用 toBeCalledWith() 测试参数

Python 使用 mock 进行多个用户输入

c# - 测试 Entity Framework 查找方法

Azure 使用 Terraform 将安全组与多个网络接口(interface)和负载均衡器与多个子网关联

azure-devops - 默认取消选择阶段

azure - 在 Azure Devops 中,有没有办法使构建/工作目录在作业之间持久存在?

powershell - 使用 TFS vNext 任务 : A parameter cannot be found that matches parameter name 的问题

Azure DevOps - 比较不同分支的代码覆盖率

azure-devops - 为 Azure Wiki 中的表行着色