Need help for displaying coverage history

I am currently working on implementing the code coverage package on our projects on DevOps. The basic functionality works, but I cannot get the coverage history graph or risk hotspots to show in DevOps.

The current steps are as follows:

  1. Run edit mode tests, publish file to folder.
  2. Convert the Unity OpenCover files to Cobertura with ReportGenerator tool. historydir input is set, and each run creates a new xml file. reports input is set to opencov/EditMode subfolder xml.
  3. Coverage results is published with PublishCodeCoverageResults task.

I have run the pipeline around 20-30 times with different variations of parameters, and also with disable.coverage.autogenerate. This did not seem to work either, and also removed the styling for the coverage page.

Any ideas or pointers on what to do?

1 Like

Currently it looks something like this. Have also tried to add
generateHtmlReport;generateHtmlReportHistory and coverageHistoryPath to Unity arguments, but should not be needed as I understand it, as this is overriden by report generator anyway.

- powershell: |

    $logFile = New-Item -Path .\editmode-test-run.log -ItemType File -Force

    $proc = Start-Process -FilePath $env:UNITY_EXE_PATH -PassThru -ArgumentList "
        -projectPath $env:PROJECT_PATH
        -runTests
        -testPlatform editmode
        -debugCodeOptimization
        -enableCodeCoverage
        -coverageResultsPath .\test-coverage-results
        -coverageOptions generateAdditionalMetrics;pathFilters:$env:COVERAGE_PATH_FILTERS
        -batchmode
        -logFile $($logFile.Name)
        -editorTestsResultFile .\test-editmode-default.xml"
 
    $ljob = Start-Job -ScriptBlock { param($log) Get-Content "$log" -Wait } -ArgumentList $logFile.FullName

    while (-not $proc.HasExited -and $ljob.HasMoreData)
    {
        Receive-Job $ljob
        Start-Sleep -Milliseconds 500
    }
    Receive-Job $ljob

    Stop-Job $ljob

    Remove-Job $ljob
    Stop-Process $proc
    exit $proc.ExitCode
  displayName: 'Run EditMode tests'
  env:
    UNITY_EXE_PATH: '${{parameters.unityInstallFolder}}$(unitygetprojectversion.projectVersion)${{parameters.unityEditorPath}}'
    PROJECT_PATH: ${{ parameters.projectPath }}
    COVERAGE_PATH_FILTERS: ${{ parameters.testCoveragePathFilters }}

- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@4
  displayName: 'Convert coverage report'
  inputs:
    reports: $(Build.SourcesDirectory)\test-coverage-results\*-opencov\EditMode\*.xml;
    targetdir: $(Build.SourcesDirectory)\test-coverage
    reporttypes: 'Cobertura'
    historydir: C:\coverage-history\${{parameters.packageName}}
    #customSettings: 'settings:renderPngFallBackImagesForHistoryCharts=true'

# Publish test results:
- task: PublishTestResults@2
  displayName: 'Publish test results'
  inputs:
    testResultsFormat: NUnit
    testResultsFiles: 'test*.xml'
    failTaskOnFailedTests: true

# Publish code coverage results
- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage results'
  inputs:
    codeCoverageTool: 'cobertura'
    summaryFileLocation: '$(Build.SourcesDirectory)\test-coverage\Cobertura.xml'

After 47 runs of the pipeline it worked! I set disable.coverage.autogenerate to true, generated HtmlInline_AzureDevops;Cobertura reports from ReportGenerator, and added the reportDirectory in PublishCodeCoverageResults task.

1 Like

Hi @mwarvik - I am glad you resolved it! I wanted to add that currently for pathFilters only absolute paths are supported. However, you can use globbing to make them shorter e.g. **/Assets/Scripts/. We are exploring allowing relative paths in a future release.

1 Like

As it is now, it works fine for our use case :slight_smile: We just include everything in Packages folder by default (eg ‘+/Packages/’), with an optional parameter that can be sent in for special cases.