Вкладка покрытия кода не отображается в Azure DevOps - PullRequest
0 голосов
/ 06 февраля 2020

У меня относительно простой тестовый проект под Azure DevOps, и я хочу создать покрытие кода.

Это работает ... вроде. Я получаю это:

Azure DevOps Code coverage

Я получаю нужные мне файлы (думаю, по крайней мере), но вкладка отсутствует.

I Выполните следующие три шага:

Выполните. NET тестовое задание. Установите генератор отчетов. Запустите генератор отчетов для преобразования (-reporttypes: HtmlInline_AzurePipelines; Cobertura ") publi sh result (s)

Но вкладка не отображается? Есть идеи?

    - 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\

Я пробовал с генератором кода, без, включить переменную покрытия кода или отключить, пробовал с генератором отчетов и без ...

1 Ответ

0 голосов
/ 07 февраля 2020

Вы можете попробовать ниже yaml to publi sh покрытие кода.

Сначала вам нужно убедиться, что ваш проект ссылается на пакет nuget coverlet.msbuild

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

Затем в вашем do tnet тестовое задание для включения 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()

Вы также можете обратиться к этому блогу .

...