1
votes

I am trying to publish the code coverage result for .NET framework 4.6.1 in Azure DevOps. I am using visual studio test task to run unit test cases and get the code coverage. After successful execution of Visual studio test task, I am getting a code coverage result in a '.coverage file'.I have opened the coverage file in visual studio in my laptop and verified it shows the number of line covered and not covered in unit test.

Using vstest.console.exe I am converting the coverage file to xml and using report generator to publish the code coverage result.

Run codecoverage.exe ReportGenerator Task settings

After successfully completed the above steps, when i click code coverage tab i am presented with html link to download the coverage file. I want to publish the coverage file in the code coverage tab itself.

Empty Code Coverage page

I have also tried this as well other similar problem, when i try, i am getting a coverage.cobertura.xml with 1kb doesn't have any details about code covered in unit test.

&dotnet tool install dotnet-reportgenerator-globaltool --tool-path . --version 4.0.12
&dotnet tool install coverlet.console --tool-path . --version 1.4.1

"`nmake reports dir:"
mkdir .\reports

"`nrun tests:"
$unitTestFile = gci -Recurse | ?{ $_.FullName -like "*bin\*UnitTestProject2.dll" }
Write-Host "`$unitTestFile value: $unitTestFile"

$coverlet = "$pwd\coverlet.exe"

"calling $coverlet for $($unitTestFile.FullName)"
&$coverlet $unitTestFile.FullName --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" } 
1

1 Answers

0
votes

Do you add Publish code coverage task to the pipeline? Code coverage Tab only supports code coverage data in Jacoco or Cobertura formats, result of the *.coverage file can not be shown by tables and graphs.

Add "Publish code coverage" task with these parameters:

enter image description here

Here is some tickets(case1,case2) with similar issue you can refer to.