【发布时间】:2021-05-25 09:15:12
【问题描述】:
我正在尝试在 Azure DevOps 中发布 .NET 框架 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" }
【问题讨论】:
标签: azure-devops