您好,我正在尝试在 azure 管道中使用 .net5 获取代码覆盖率。
运行测试(不是整个文件)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Results File: /home/vsts/work/_temp/_fv-az43-964_2021-08-25_08_31_59.trx
Attachments:
/home/vsts/work/_temp/f5dd5e9f-e260-437d-80ef-4fb917215b09/coverage.cobertura.xml
Passed! - Failed: 0, Passed: 16, Skipped: 0, Total: 16, Duration: 732 ms - /home/vsts/work/1/s/sda2021_webapi/Test/sda2021_api.tests/bin/Release/net5.0/sda2021_webapi.tests.dll (net5.0)
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
Async Command Start: Publish test results
Publishing test results to test run '5152'.
TestResults To Publish 16, Test run id:5152
Test results publishing 16, remaining: 0. Test run id: 5152
Published Test Run : https://dev.azure.com/sda-shs/Bratislava2021/_TestManagement/Runs?runId=5152&_a=runCharts
Async Command End: Publish test results
Finishing: Dotnet run tests
发布测试(不是整个文件)
##[warning]Multiple file or directory matches were found. Using the first match: /home/vsts/work/_temp/_fv-az43-964_2021-08-25_08_31_59/In/fv-az43-964/coverage.cobertura.xml
/opt/hostedtoolcache/dotnet/dotnet /home/vsts/work/_tasks/PublishCodeCoverageResults_2a7ebc54-c13e-490e-81a5-d7561ab7cd97/1.189.0/netcoreapp2.0/ReportGenerator.dll -reports:/home/vsts/work/_temp/**/coverage.cobertura.xml -targetdir:/home/vsts/work/_temp/cchtml -reporttypes:HtmlInline_AzurePipelines
2021-08-25T08:32:03: Arguments
2021-08-25T08:32:03: -reports:/home/vsts/work/_temp/**/coverage.cobertura.xml
当然还有我的管道
task: DotNetCoreCLI@2
displayName: Dotnet run tests
inputs:
command: "test"
projects: "**/xxxxx/*.tests.csproj"
arguments: '--configuration Release /p:CoverletOutputFormat=cobertura --collect:"XPlat Code Coverage" --no-build'
testRunTitle: "xxxx"
- task: PublishCodeCoverageResults@1
displayName: "publish coverage results"
inputs:
codeCoverageTool: "Cobertura"
summaryFileLocation: "$(Agent.TempDirectory)/**/coverage.cobertura.xml"
为什么会生成多个 XML?我基本上在没有 XML 和更多 XML 之间进行平衡。我只是无法生成一个 XML。 (在我的本地主机上它只生成一个)感谢您的任何提示。
更新 06.05.2024
您可以使用版本 2,它允许您传递多个文件而无需先合并它们:
- task: PublishCodeCoverageResults@2
displayName: 'Publish code coverage results'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
summaryFileLocation - 摘要文件的路径
指定包含代码覆盖率统计信息的摘要文件的路径,例如行、方法和类覆盖率。多个摘要文件合并为一个报告。该值可能包含最小匹配模式。例如:$(System.DefaultWorkingDirectory)/MyApp/**/site/cobertura/coverage.xml
旧答案
请按照以下步骤替换您的
PublishCodeCoverageResults
:
- task: reportgenerator@4
displayName: 'Merge code coverage reports'
inputs:
reports: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'
targetdir: '$(Pipeline.Workspace)/coverlet'
reporttypes: 'Cobertura'
verbosity: 'Verbose'
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage results'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Pipeline.Workspace)/coverlet/Cobertura.xml'
并且您有多个文件,因为您可能有多个测试项目。
如果您不想使用 ReportGenerator,请使用任务的版本 2
PublishCodeCoverageResults@2
,您将不会收到该警告。
- task: DotNetCoreCLI@2
displayName: Dotnet test with code coverage
inputs:
command: test
projects: <your project path>
arguments: --collect:"XPlat Code Coverage"
- task: PublishCodeCoverageResults@2
displayName: Publish code coverage results
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: $(Agent.TempDirectory)/**/coverage.cobertura.xml