How to set a custom coverage result file path when running dotnet test --collect “Code coverage”?

好久不见. 提交于 2021-01-29 18:50:02

问题


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.

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:

  1. Download the https://www.nuget.org/packages/Microsoft.CodeCoverage/ package and locate CodeCoverage.exe inside.
  2. Run CodeCoverage.exe to convert the binary coverage result to the respective XML.
  3. Install the reportgenerator dotnet tool
  4. Run the reportgenerator tool to convert that XML to Cobertura
  5. 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?


回答1:


Found it. Three things need to be done:

  1. Turn off automatic publishing the test results from the DotNetCoreCLI@2 test command. This prevents it from injecting its own result directory.
  2. Pass your own directory in the -r parameter.
  3. 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"'

And the coverage result would be $(Build.StagingDirectory)\tests\<SOME GUID>\*.coverage



来源:https://stackoverflow.com/questions/61089491/how-to-set-a-custom-coverage-result-file-path-when-running-dotnet-test-collect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!