在 azure devops 门户上查看代码覆盖率报告 [英] view code coverage report on azure devops portal

查看:31
本文介绍了在 azure devops 门户上查看代码覆盖率报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行 NUnit 测试(.Net Framework 4.5 中的项目),作为 azure devops 构建管道的一部分.

- 任务:VSTest@2输入:testAssemblyVer2: 'tests/**/*.Tests.dll'pathtoCustomTestAdapters: '$(Build.SourcesDirectory)/packages'codeCoverageEnabled: 真displayName: 'NUnit 测试'- 任务:PublishCodeCoverageResults@1输入:代码覆盖工具:JaCoCosummaryFileLocation: '$(Common.TestResultsDirectory)/**/*.xml'displayName: '发布代码覆盖率'//summaryFileLocation: '$(Common.TestResultsDirectory)/**/*.coverage'

但是我看不到覆盖率报告,只能看到覆盖率结果的下载链接...

如何将 .coverage 报告转换为 JaCoCo 格式?还是直接以 JaCoCo 格式生成报告?

我已经看到了 .Net Core 的一些解决方案(



直接安装工具

使用 Powershell 任务(或类似任务)直接安装 Coverlet报告生成器 工具.这允许您在非 .Net Core 的项目中使用它们.

安装工具:"&dotnet 工具安装 dotnet-reportgenerator-globaltool --tool-path .--版本 4.0.12&dotnet 工具安装 coverlet.console --tool-path .--版本 1.4.1



通过coverlet使用dotnet vstest

据我所知,dotnet test 不能很好地与 .Net Framework 项目/程序集配合使用.但是,我们仍然可以使用 dotnet 命令,我们知道它会在代理机器上,但是我们需要使用它作为一种机制来访问 vstest.console.exeem>.

Coverlet 工具(如您链接的文章中所述)会以 Cobertura 格式输出覆盖率结果(如果您告诉它这样做).

&$coverlet $unitTestFile.FullName --target dotnet"--targetargs "vstest $($unitTestFile.FullName) --logger:trx";--格式cobertura"



发布结果



完整的脚本示例

注意:这个脚本非常粗糙,所以将其用作针对您个人情况的思考练习.

安装工具:"&dotnet 工具安装 dotnet-reportgenerator-globaltool --tool-path .--版本 4.0.12&dotnet 工具安装 coverlet.console --tool-path .--版本 1.4.1`nmake 报告目录:"mkdir .
eports`nrun 测试:"$unitTestFile = gci -Recurse |?{ $_.FullName -like "*bin*UnitTestProject2.dll";}写入主机`$unitTestFile 值:$unitTestFile";$coverlet = "$pwdcoverlet.exe";为 $($unitTestFile.FullName) 调用 $coverlet";&$coverlet $unitTestFile.FullName --target dotnet"--targetargs "vstest $($unitTestFile.FullName) --logger:trx";--格式cobertura"生成报告"gci -Recurse |?{ $_.Name -eq "coverage.cobertura.xml";} |%{ &$pwd
eportgenerator.exe";"-reports:$($_.FullName)";-targetdir:reports"-reporttypes:HTMLInline;HTMLChart"}


如果您正在努力使用 Coverlet 命令找出引号的转义等问题,






原答案:


由于您提到的链接文章安装和使用报告生成器全局工具的方式,我认为您仍然可以遵循这些指南来创建 HTML 内联和图表报告类型.

我不确定文章所说的意思或它是如何工作的,

<块引用>

重点是报告类型:使用 HTMLInLine 启用 Azure DevOps 页面上的输出.Azure DevOps Coverage 页面在网络上显示 index.html.

我了解到您可以使用该工具从 .xml 覆盖率结果创建 HTML 报告,然后将覆盖率结果和报告与 Publish Code Coverage<一起发布/code> 任务.

因此,您似乎只需要一个 .xml 格式的 .coverage 工具.

我没有在直接的 powershell 中使用它,但是您可以按照 报告生成器文档,用于编写 C# 实用程序以访问 Coverage.Analysis 库.

I am running the NUnit tests (project in .Net Framework 4.5), as part of azure devops build pipeline.

- task: VSTest@2
  inputs:
    testAssemblyVer2: 'tests/**/*.Tests.dll'
    pathtoCustomTestAdapters: '$(Build.SourcesDirectory)/packages'
    codeCoverageEnabled: true
  displayName: 'NUnit Testing'

- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: JaCoCo
    summaryFileLocation: '$(Common.TestResultsDirectory)/**/*.xml'
  displayName: 'Publish Code Coverage'
  //        summaryFileLocation: '$(Common.TestResultsDirectory)/**/*.coverage'

But I am not able to see the coverage report, all I see the download link for coverage results...

How can I convert the .coverage report to JaCoCo format? OR generate the report directly in JaCoCo format?

I have seen some solution for .Net Core (link), but none for .Net framework

解决方案

Update:

As per the release to Azure Devops for Sprint 150

When publishing code coverage reports, you no longer need to specify HTML files.

Therefore, the script in my illustration no longer needs to use the report generator tool directly to create the html report, and when publishing the coverage results, the directory containing those html reports doesn't need to be specified.

Edit:


The trick I've found for getting the coverage results from a .Net Framework project to show up on the Code Coverage tab is in the same line of thought to your linked article.

  1. Don't run tests with the VS Test Task in Azure
  2. Install the Report Generator and Coverlet tools directly
  3. Use dotnet-vstest command for running tests through Coverlet
  4. Publish reports generated with Report Generator and Cobertura format coverage results



Don't use the VS Test Task

Running this task will allow you to collect coverage with a simple checkbox, but you then surrender your opportunity to provide the content for the Code Coverage Tab



Install tools directly

Use a Powershell task (or similar) to install the Coverlet and Report Generator tools directly. This allows you to use them on projects that are not .Net Core.

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



Use dotnet vstest through coverlet

It's my understanding that dotnet test doesn't play nice with .Net Framework projects/assemblies. However, we can still use the dotnet command, which we know will be on the agent machine, but we need to use it as a mechanism to get to the vstest.console.exe.

The Coverlet tool, as mentioned in the article you linked, will output coverage results in Cobertura format if you tell it to do so.

&$coverlet $unitTestFile.FullName --target "dotnet" --targetargs "vstest $($unitTestFile.FullName) --logger:trx" --format "cobertura"



Publish results



Complete script sample

note: this script is pretty rough, so use it as a thought exercise for your individual situation.

"install tools:"
&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 .
eports

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

$coverlet = "$pwdcoverlet.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
eportgenerator.exe" "-reports:$($_.FullName)" "-targetdir:reports" "-reporttypes:HTMLInline;HTMLChart" }


If you're struggling to figure out the escaping of quotes and such with the Coverlet command, YOU ARE NOT ALONE. I used the echoargs commandlet from PSCX more times than I care to admit so I could see what was actually getting provided to the .exe calls I was making.



The Results!!

...because that's really what matters






Original Answer:


Because of the way the linked article you mentioned is installing and using the report generator global tool I would think you can still follow those guidelines for creating the HTML inline and chart report types.

I'm not sure what is meant or how it works when the article says,

The point is the reporttypes: Use HTMLInLine for enabling the output on the Azure DevOps page. Azure DevOps Coverage page show index.html on the web.

I'm understanding that you can use the tool to create the HTML report from the .xml coverage results, and then publish the coverage results and report together with the Publish Code Coverage task.

So it seems all you need is to have an .xml format of the .coverage tool.

I didn't get it working in straight powershell, but you could follow the instructions from the Report Generator documentation to write a C# utility to access the Coverage.Analysis library.

这篇关于在 azure devops 门户上查看代码覆盖率报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆