0

We would like to block the pull requests when its not meet the code coverage.

So we enabled the branch policy status check and assiged the PR pipe line.

After that the code coverag report is not displaying

Inside the code coverage tab only download option is avilable.

Is there any way to display the code covrage report?

Yaso
  • 21
  • 1
  • is this the answer you are looing for? https://stackoverflow.com/questions/64592534/publish-a-pipeline-azure-devops-code-coverage-report/68503501#68503501 – h0p3zZ Sep 06 '21 at 13:10

2 Answers2

0

Is there any way to display the code covrage report?

When you use VStest task to generate the Code Coverage report, the format is .coverage file. It doesn't support to show in the Code Coverage tab.

To display the code coverage report, you need to generate the cobertura format code coverage report.

For .netFramework project, you need to use Powershell to run the test the generate the cobertura report.

For example:

"install tools:"
&dotnet tool install dotnet-reportgenerator-globaltool --tool-path . 
&dotnet tool install coverlet.console --tool-path . --version 1.4.1

"`nmake reports dir:"
mkdir .\reports

"`nrun tests:"

Write-Host "`$unitTestFile value: $unitTestFile"

$coverlet = "$pwd\coverlet.exe"

"calling $coverlet for $($unitTestFile.FullName)"
&$coverlet "$(build.sourcesdirectory)/Bank1/Banktest/bin/release/xx.dll(DLL Path)" --target "dotnet" --targetargs "vstest $($unitTestFile.FullName) --logger:trx" --format "cobertura"

"`ngenerate report(s)"
gci -Recurse | 
    ?{ $_.Name -eq "coverage.cobertura.xml" } | 
    %{ &"$pwd\reportgenerator.exe" "-reports:$($_.FullName)" "-targetdir:reports" "-reporttypes:HTMLInline;HTMLChart" }

enter image description here

Result:

enter image description here

For .Net Core project:

You can try the following sample:

- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '$(Parameters.TestProjects)'
    arguments: '--configuration $(BuildConfiguration) --collect:"XPlat Code Coverage" '

- script: 'dotnet tool install -g dotnet-reportgenerator-globaltool  '
  displayName: 'Command Line Script'

- script: 'reportgenerator -reports:$(Agent.TempDirectory)/**/coverage.cobertura.xml -targetdir:$(build.sourcesdirectory) -reporttypes:"Cobertura"'
  displayName: 'Command Line Script'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage from $(build.sourcesdirectory)/Cobertura.xml'
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(build.sourcesdirectory)/Cobertura.xml'

For more detailed info, you can refer to these two tickets: Case1 and Case2

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
  • 1
    0 Thank for your answer, we have the task to convert the .coverage to Cobertura.xml, And it shows correctly before the code coverage status check. Once the status check is finished the display of report disapears and shows the download link. Any idea? – Yaso Sep 08 '21 at 09:01
  • Do you enable the code coverage option in VSTest task? If yes, you need to disable the option – Kevin Lu-MSFT Sep 08 '21 at 09:07
0

Thank for your answer, we have the task to convert the .coverage to Cobertura.xml, And it shows correctly before the code coverage status check. Once the status check is finished the display of report disapears and shows the download link.

Any idea?

Yaso
  • 21
  • 1