Aakash Parmar
Aakash Parmar

Reputation: 1

How do i get code coverage on azure pipeline using coverlet and cobertura config?

I am trying to write YAML file for code coverage.

What is the correct way to get code coverage for my project in Azure pipelines using coverlet and cobertura configurations?

I have followed the same steps as running locally with CLI commands, but I am still getting zero coverage. My arguments are as follows:

--configuration $(buildConfiguration) --collect:"XPlat Code Coverage" --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:Exclude="[xunit.*]*" /p:CoverletOutput=$(System.DefaultWorkingDirectory)\coverage. 

Should I exclude my project while running the code coverage command? Any ideas on what might be wrong with my commands?

I tried all the steps found on internet. I verified commands comparing with the commands running locally in CMD with same commands.

Upvotes: 0

Views: 1240

Answers (1)

wade zhou - MSFT
wade zhou - MSFT

Reputation: 8127

I can reproduce with same arguments for dotnet test:

- task: DotNetCoreCLI@2
  displayName: dotnet test
  inputs:
    command: 'test'
    arguments: '--configuration Release --collect:"XPlat Code Coverage" --logger trx /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:Exclude="[xunit.*]* /p:CoverletOutput=$(System.DefaultWorkingDirectory)\coverage'

enter image description here

For Xplat Code Coverage, you need to add PublishCodeCoverageResults@2 task after the test task, so that it will publish the coverage from the build.

- task: PublishCodeCoverageResults@2
  inputs:
    summaryFileLocation: |
      $(Agent.TempDirectory)\**\coverage.*.xml

enter image description here

Note: checked on my side, even you have specified /p:CoverletOutput, it will still generate the coverage.cobertura.xml in $(Agent.TempDirectory) folder.

Upvotes: 0

Related Questions