我正在尝试在 Azure DevOps 中发布 .NET framework 4.6.1 的代码覆盖率结果。我正在使用 Visual Studio 测试任务来运行单元测试用例并获取代码覆盖率。成功执行 Visual Studio 测试任务后,我在“.coverage 文件”中得到了代码覆盖率结果。我在笔记本电脑中的 Visual Studio 中打开了覆盖率文件并验证它显示了单元中覆盖和未覆盖的行数测试。
使用 vstest.console.exe 我将覆盖文件转换为 xml 并使用报告生成器发布代码覆盖结果。
成功完成上述步骤后,当我单击代码覆盖率选项卡时,我会看到 html 链接以下载覆盖率文件。我想在代码覆盖率选项卡本身中发布覆盖率文件。
我也尝试过这个other similar problem,当我尝试时,我得到了一个 1kb 的coverage.cobertura.xml 没有关于单元测试中涵盖的代码的任何详细信息。
&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" }