I have an Azure DevOps pipeline that validates pull requests. I have configured dotnet test
to collect code coverage metrics using the --collect "Code coverage"
argument:
- task: DotNetCoreCLI@2
displayName: dotnet test
inputs:
command: 'test'
arguments: '--configuration $(BuildConfiguration) --collect "Code coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura'
workingDirectory: $(baseWorkingDirectory)
projects: 'tests/**/*.csproj'
nobuild: true
As you can see, I'm also passing /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
. This I have to do in order to generete a coverage report:
- task: CmdLine@2
inputs:
script: dotnet tool install -g dotnet-reportgenerator-globaltool
- task: CmdLine@2
inputs:
script: reportgenerator -reports:$(Build.SourcesDirectory)/tests/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines;Cobertura
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/Cobertura.xml'
reportDirectory: '$(Build.SourcesDirectory)/CodeCoverage'
Documentation states that code coverage for pull requests is available only using the Visual Studio code coverage results format (file extension .coverage)
So:
- I have to use Visual Studio code coverage
--collect:"Code Coverage"
to get code coverage for pull requests, because Cobertura format won't work. - I need to use Cobertura format in order to get a readable report on the Code Coverage tab in the pipeline, but the Cobertura report won't show up if I use
--collect:"Code Coverage"
at the same time.
It seems I can't get both code coverage for PRs and a full report in Cobertura format at the same time.
Other people seem to have the same problem, but the issue wasn't resolved in that thread.
Am I missing something?