【问题标题】:Code coverage tab not showing in Azure DevOpsAzure DevOps 中未显示代码覆盖率选项卡
【发布时间】:2020-05-22 19:31:37
【问题描述】:

我在 Azure DevOps 下有一个相对简单的测试项目,我想生成代码覆盖率。

这行得通……有点。我明白了:

我得到了我需要的文件(至少我认为)但是标签不见了。

我有这三个步骤:

做 .NET 测试任务 安装报告生成器 运行报告生成器进行转换 (-reporttypes:HtmlInline_AzurePipelines;Cobertura") 发布结果

但是标签没有显示?有什么想法吗?

    - stage: Run_Unit_tests 
  jobs:
  - job: 'Tests'
    pool: 
      vmImage: 'windows-latest'
    variables:
      buildConfiguration: 'Release'
    continueOnError: true
    steps:
    - task: DotNetCoreCLI@2
      inputs:
        command: custom
        custom: tool
        arguments: install --tool-path . dotnet-reportgenerator-globaltool
      displayName: Install ReportGenerator tool

    - task: DotNetCoreCLI@2
      displayName: Test .NET
      inputs:
        command: test
        projects: '**/*Test/*.csproj'
        arguments: '--configuration $(buildConfiguration) --logger trx --collect:"XPlat Code Coverage"'
      condition: succeededOrFailed()

    - task: reportgenerator@4
      inputs:
        reports: '$(Agent.TempDirectory)\**\coverage.cobertura.xml'
        targetdir: '$(Build.SourcesDirectory)\coverlet\reports'
        verbosity: 'Verbose'
    - task: PublishCodeCoverageResults@1
      displayName: 'Publish code coverage'
      inputs:
        codeCoverageTool: Cobertura
        summaryFileLocation: $(Build.SourcesDirectory)\coverlet\reports\Cobertura.xml
        failIfCoverageEmpty: false
        reportDirectory: $(Build.SourcesDirectory)\coverlet\reports\

我尝试使用代码生成器,没有,启用代码覆盖变量或禁用,尝试使用报告生成器,但没有...

【问题讨论】:

  • 除非您提供更多细节,否则很难回答您的问题。理想情况下,您的 pipeline.yml 步骤。看到这个问题stackoverflow.com/questions/54627918/…
  • 嗨@Unomagan 你检查下面的 yml 了吗?如果有任何问题,请告诉我。
  • 不,没有,在这一点上我现在要放弃......也许稍后
  • 嗨@Unomagan 如果有机会请查看以下步骤,这不是很复杂。我通过以下步骤成功获得了管道上显示的代码覆盖率
  • 我对此表示赞同...我有一个覆盖选项卡的屏幕截图。当我回到 devops 中的 same run 时,不再有选项卡了!

标签: azure azure-devops devops


【解决方案1】:

我也遇到了这个问题,并追踪到我的管道中混合了 VS 测试和 dotnet 测试任务。一旦我删除了 VS Test 任务,它就全部工作了。

似乎 VS Test 任务上传了自己的代码覆盖率结果,并且发布 cobertura 结果+这个 VS Test 任务的组合混淆了 Azure Devops。

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题,按F5就出现了!

    这很疯狂,但它实际上始终如一地这样做。

    devops 前端代码中似乎偶尔会出现错误?

    【讨论】:

    • 最苦乐参半的答案
    【解决方案3】:

    您可以尝试以下 yaml 发布代码覆盖率。

    首先你需要确保你的项目引用了 nuget 包 coverlet.msbuild

    <PackageReference Include="coverlet.msbuild" Version="2.5.1">
          <PrivateAssets>all</PrivateAssets>
          <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
        </PackageReference>
    

    然后在您的 dotnet 测试任务 中启用 CollectCoverage

    arguments: '/p:CollectCoverage=true /p:CoverletOutput=$(Build.SourcesDirectory)\TestResult\ /p:CoverletOutputFormat=cobertura'
    

    然后在reportgenerator任务中指定reports文件夹到CoverletOutput文件夹reports: '$(Build.SourcesDirectory)\TestResult\**\coverage.cobertura.xml'

    请查看以下 yaml 以供参考:

    steps:
      - task: UseDotNet@2
        inputs:
          version: 2.2.x 
    
      - task: DotNetCoreCLI@2
        inputs:
          command: restore
          projects: '**\*.csproj'
    
      - task: DotNetCoreCLI@2
        inputs:
          command: custom
          custom: tool
          arguments: install --tool-path . dotnet-reportgenerator-globaltool
        displayName: Install ReportGenerator tool
    
      - task: DotNetCoreCLI@2
        displayName: Test .NET
        inputs:
          command: test
          projects: '**\*Test*.csproj'
          publishTestResults: false
          arguments: '--configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutput=$(Build.SourcesDirectory)\TestResult\ /p:CoverletOutputFormat=cobertura'
        condition: succeededOrFailed()
    
      - task: reportgenerator@4
        inputs:
          reports: '$(Build.SourcesDirectory)\TestResult\**\coverage.cobertura.xml'
          targetdir: '$(Build.SourcesDirectory)\coverlet\reports'
          verbosity: 'Verbose'
    
        condition: succeededOrFailed()
      - task: PublishCodeCoverageResults@1
        displayName: 'Publish code coverage'
        inputs:
          codeCoverageTool: Cobertura
          summaryFileLocation: $(Build.SourcesDirectory)\coverlet\reports\Cobertura.xml
          failIfCoverageEmpty: false
          reportDirectory: $(Build.SourcesDirectory)\coverlet\reports\
        condition: succeededOrFailed()
    

    您也可以参考这个blog

    【讨论】:

    • 嘿@levi-lu-msft - 这似乎不再起作用:/报告已生成但不可见。也不清楚如何让它与多个测试程序集一起工作 - 每个都生成一个 TestResults\Coverage\coverage.cobertura.xml 文件,所以 dotnet test 似乎正在覆盖它们
    • 您可以通过执行以下操作使其生成单个 xml 文件:将输出格式设置为 cobertura,json 然后设置 MergeWith=OutputDir\coverage.json 然后它将合并所有 json 文件并作为它会重新生成包含合并内容的 xml 文件。您可能需要稍微调整一下设置,但这通常是您的做法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-17
    • 2020-11-25
    • 2021-09-27
    • 2021-08-13
    • 2020-02-13
    • 2022-01-12
    相关资源
    最近更新 更多