VSTS编码器覆盖率未显示HTML报告

时间:2019-04-03 16:33:00

标签: azure azure-devops azure-pipelines-build-task

我正在尝试配置VSTS Build来运行我们的集成测试并生成代码覆盖HTML报告。我正在使用Coverlet和ReportGenerator插件来完成此操作。这就是我现在配置构建的方式:

    pool:
  name: Hosted VS2017
  demands:
  - msbuild
  - visualstudio

steps:
- task: NuGetToolInstaller@0
  displayName: 'Use NuGet 4.7.1'
  inputs:
    versionSpec: 4.7.1

- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '$(Parameters.solution)'

- task: VSBuild@1
  displayName: 'Build solution'
  inputs:
    solution: '$(Parameters.solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: 'Run Integration Tests'
  inputs:
    command: test
    arguments: '-c $(BuildConfiguration)  /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)\TestResults\Coverage\ --no-build'

- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@1
  displayName: ReportGenerator
  inputs:
    reports: '$(Build.SourcesDirectory)\TestResults\Coverage\coverage.cobertura.xml'
    targetdir: '$(Build.SourcesDirectory)\coveragereport'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage results'
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(Build.SourcesDirectory)\coveragereport\Cobertura.xml'
    reportDirectory: '$(build.sourcesdirectory)\src\target\reports\coverage'

- task: PublishSymbols@1
  displayName: 'Publish symbols path'
  inputs:
    SearchPattern: '**\bin\**\*.pdb'
  continueOnError: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'
    ArtifactName: '$(Parameters.ArtifactName)'

我不确定我在哪里出错,但是构建似乎已经完成,没有任何错误,但是我仍然看不到代码覆盖范围选项卡中的任何内容。你能解释我在想什么吗?

1 个答案:

答案 0 :(得分:1)

好的,我终于可以在这篇文章的帮助下解决问题

https://www.meziantou.net/2019/02/18/computing-code-coverage-for-a-net-core-project-with-azure-devops-and-coverlet

如果您非常仔细地阅读,那么报告生成器步骤的“目标目录” 需要与“发布CodeCoverage结果”任务的“报告目录” 相匹配。如果您看我最初的问题,它们是不同的,因为我的理解不正确。固定路径后,代码覆盖率开始显示在“构建代码覆盖率”选项卡中。希望它能帮助面临同样问题的人。