Where is the documentation to setup Code Coverage with Azure Devops (.net)

Template for a good new topic, formatted with Markdown:

  • ALM used (GitHub, Bitbucket Cloud, Azure DevOps) What is ALM? I’m assuming it’s Azure devops.
  • CI system used (Bitbucket Cloud, Azure DevOps, Travis CI, Circle CI - Azure devops
  • Scanner command used when applicable (private details masked)
  • Languages of the repository - eng
  • Only if the SonarCloud project is public, the URL
    • And if you need help with pull request decoration, then the URL to the PR too
  • Error observed (wrap logs/code around with triple quotes ``` for proper formatting)
  • Steps to reproduce
  • Potential workaround

Not sure if that’s exactly what you’re looking for, but this might help:

  1. Make sure you include tools to generate code coverage in your .net project, for example:
  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-reportgenerator-cli" Version="4.3.6" />
    <PackageReference Include="coverlet.collector" Version="1.2.0"/>
    <PackageReference Include="coverlet.msbuild" Version="2.8.0"/>
  </ItemGroup>
  1. Run dotnet test with the appropriate arguments, like
/p:CollectCoverage=true
/p:CoverletOutput=$(Agent.TempDirectory)\coverage\
/p:MergeWith=$(Agent.TempDirectory)\coverage\coverage.json
/p:CoverletOutputFormat="json,cobertura"
  1. Generate the coverage report
  - task: DotNetCoreCLI@2
    inputs:
      command: 'custom'
      projects: '**/*.sln'
      custom: 'reportgenerator'
      arguments: '"-reports:$(Agent.TempDirectory)\coverage\coverage.cobertura.xml" "-targetdir:$(Agent.TempDirectory)\coverage\Reports" -tag:$(Build.BuildNumber) "-reporttypes:HTMLInline;HTMLChart;SonarQube"'
  1. Make sure Sonar is configured to point to the correct report
sonar.coverageReportPaths="$(Agent.TempDirectory)\coverage\Reports\SonarQube.xml"
2 Likes

Hi @marcl

My apologies for the late answer, this wasn’t tagged dotnet so we missed it.

We do have some community guides:

And unrelated to the code coverage import:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.