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.
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.
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" }