Shu*_*bho 4 opencover azure-devops azure-pipelines-build-task azure-pipelines azure-pipelines-tasks
我需要指导来在azure构建管道中生成Asp.net单元测试的代码覆盖率报告。我的项目基于.Net Framework 4.6。
我可以使用“ Visual Studio测试”任务来运行所有单元测试。
我尝试了“报告生成器”任务,但是它需要cobertura或jacoco等xml文件,这些文件无法在构建管道中生成。
期望-我想获得运行的单元测试的代码覆盖率报告,该报告将显示完整的信息,例如行覆盖率,分支覆盖率,功能覆盖率等,与“报告生成器”生成的信息相同。
注意:我能够在本地系统上使用opencover和reportgenerator生成报告,但是无法找到在Azure构建管道中执行相同操作的方法。
要获得.Net框架中的代码覆盖率结果,您只需在“ Visual Studio Test”任务中启用它即可:
如果您使用.yml的是构建,则语法为:
- task: VSTest@2
inputs:
codeCoverageEnabled: true
Run Code Online (Sandbox Code Playgroud)
结果:
注意:如果使用Microsoft Hosted Agent,将看到结果;如果使用Self Hosted Agent,则必须是Visual Studio Enterprise版本才能看到代码覆盖率结果。
如果您想要更详细的代码覆盖率报告,则可以coverlet在.Net框架中使用,方法是在管道中安装该工具,然后生成报告。您可以使用PowerShell脚本执行以下操作:
dotnet tool install dotnet-reportgenerator --tool-path . --version 4.0.12
dotnet tool install coverlet.console --tool-path . --version 1.4.1
mkdir .\reports
$unitTestFile = gci -Recurse | ?{ $_.FullName -like "*bin\*test*.dll" }
$coverlet = "$pwd\coverlet.exe"
& $coverlet $unitTestFile.FullName --target "dotnet" --targetargs "vstest $($unitTestFile.FullName) --logger:trx" --format "cobertura"
gci -Recurse |
?{ $_.Name -eq "coverage.cobertura.xml"} |
%{ &"$pwd\reportgenerator.exe" "-reports:$($_.FullName)" "-targetdir:reports" "-reportstypes:HTMLInline;HTMLChart" }
Run Code Online (Sandbox Code Playgroud)
然后使用以下参数添加“发布代码覆盖率”任务:
结果:
| 归档时间: |
|
| 查看次数: |
771 次 |
| 最近记录: |