在运行dotnet测试-收集“代码覆盖率"时,如何设置自定义覆盖率结果文件路径? [英] How to set a custom coverage result file path when running dotnet test --collect "Code coverage"?
问题描述
I followed the instructions on http://tdc1tfsapp01:8080/tfs/DefaultCollection/SharpTop/_packaging?_a=package&feed=dayforce&package=OrchardCore.Cms.Web&version=1.0.20098.7+1bcd36b1f8efd5484af49f8ec39c21060a64391e&protocolType=NuGet and it does produce a binary coverage result file and surfaces a link to it on the build.
但是,我想将其转换为Cobertura以便在构建本身上发布.这是一个相当复杂的过程,需要:
But, I want to convert it to Cobertura in order to publish on the build itself. It is a rather convoluted process, where one needs to:
- 下载 https://www.nuget.org/packages/Microsoft.CodeCoverage/包,然后在其中找到CodeCoverage.exe.
- 运行CodeCoverage.exe,将二进制coverage结果转换为相应的XML.
- 安装reportgenerator dotnet工具
- 运行reportgenerator工具将XML转换为Cobertura
- 最后我们可以发布到构建版本
- Download the https://www.nuget.org/packages/Microsoft.CodeCoverage/ package and locate CodeCoverage.exe inside.
- Run CodeCoverage.exe to convert the binary coverage result to the respective XML.
- Install the reportgenerator dotnet tool
- Run the reportgenerator tool to convert that XML to Cobertura
- Finally we can publish to the build
我的问题是我不知道在生成过程中将二进制结果放在何处.所以,我的问题是-我们可以自定义其位置吗?
My problem is that I do not know where the binary result is placed during the build. So, my question is - can we customize its location?
推荐答案
找到了它.需要完成三件事:
Found it. Three things need to be done:
- 关闭通过
DotNetCoreCLI @ 2 test
命令自动发布测试结果的功能.这样可以防止其注入自己的结果目录. - 在
-r
参数中传递您自己的目录. - 添加明确的任务以发布测试结果.
- Turn off automatic publishing the test results from the
DotNetCoreCLI@2 test
command. This prevents it from injecting its own result directory. - Pass your own directory in the
-r
parameter. - Add an explicit task to publish the test results.
这是我运行测试的方式:
Here is how I run the tests:
- task: DotNetCoreCLI@2
name: Test
displayName: Test
inputs:
command: 'test'
publishTestResults: false
arguments: '-c Release --no-build -l trx -r "$(Build.StagingDirectory)\tests" --collect "Code coverage"'
覆盖范围结果为 $(Build.StagingDirectory)\ tests \< SOME GUID> \ *.coverage
这篇关于在运行dotnet测试-收集“代码覆盖率"时,如何设置自定义覆盖率结果文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!