Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to present code coverage report on Azure DevOps #29

Closed
wli3 opened this issue May 6, 2020 · 6 comments
Closed

How to present code coverage report on Azure DevOps #29

wli3 opened this issue May 6, 2020 · 6 comments
Assignees

Comments

@wli3
Copy link

wli3 commented May 6, 2020

From @SergiyKostenko on Sunday, March 22, 2020 4:25:08 PM

Hello,

Is there way to present code coverage report using DotNetCoreCLI@2 test command?
Documentation (https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops&tabs=yaml#collect-code-coverage) says
The .coverage file can be downloaded from the build summary for viewing in Visual Studio. Howewer, it is not handy to download it. I would prefer to see it on tab? Is it possible with default dotnet cli?
image

Copied from original issue: dotnet/sdk#10962

@wli3
Copy link
Author

wli3 commented May 6, 2020

From @wli3 on Wednesday, April 8, 2020 8:10:43 PM

Sorry there is not test coverage on CLI today

@wli3
Copy link
Author

wli3 commented May 6, 2020

From @eluchsinger on Wednesday, May 6, 2020 7:21:26 AM

So what does the --collect:"Code Coverage" do on dotnet test? I see a file .coverage created in my Unit Tests folder. How does the vstest approach compare to dotnet test?

There are so so many guides explaining how to collect code coverage and all of them just post commands without explaining what they do exactly. I have not found one single best practice approach in Microsoft's multiple Docs about Code Coverage.

Can we get an official advice on how to do Code Coverage? I know it's possible, what I don't know is how I should do it.

@ViktorHofer
Copy link
Member

AFAIK you can publish the coverage report with the PublishCodeCoverageResults AzDO task: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-code-coverage-results?view=azure-devops

@gioce90
Copy link

gioce90 commented Jan 21, 2022

I think that is a good point. Many guides says to use cobertura format instead of .coverage and with the ReportGenerator task is possible to presents a visual report in the build "Code coverage" tab (instead of that "Download code coverage results").
And that is ok if you want a full code coverage visible on the build BUT is a problem if you want a diff coverage on a PR . Is impossible with different formats than .coverage files. I don't see a way out.

@jakubch1 jakubch1 transferred this issue from microsoft/vstest May 22, 2023
@gioce90
Copy link

gioce90 commented May 23, 2023

I recently noticed that now the DotNetCoreCLI@2 task with command: test and publishTestResults: true just pubblish the coverage in the Coverage tab of the pipeline. Is nice, not perfect, but nice.

In my case I have this pipeline:

trigger: none
pr:
  branches:
    include:
    - develop

pool:
  vmImage: 'windows-2022'

variables:
  buildConfiguration: 'Release'

steps:

# restore step
  - task: DotNetCoreCLI@2
    displayName: 'dotnet restore'
    inputs:
      command: 'restore'
      projects: '**/*.csproj'
      configuration: $(BuildConfiguration)
      feedsToUse: 'select'
      vstsFeed: '_____my_feed____'

# test step
  # task: test with default code coverage (.coverage format) and publish coverage included:
  # Usefull for PR diff coverage
  - task: DotNetCoreCLI@2
    displayName: 'DotNetCoreCLI Test with report (.coverage format)'
    inputs:
      command: test
      projects: '**/**.Tests.csproj'
      arguments: '--no-restore --collect "Code Coverage"'
      publishTestResults: true

And I see this:

image

The bad thing here is that this include external NuGet packages (like Redis, fluentvalidation, moq, etc...) and also my Tests projects (as pointed out also here).... but it's still something.

There is another way, but is using cobertura coverage format, or multiple pipelines... I wrote somethings here.

@gioce90
Copy link

gioce90 commented Sep 28, 2023

I think this issue can be closed now. Right? @jakubch1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants