gpt4 book ai didi

azure - coverlet 不会在 azure devops 中创建报告

转载 作者:行者123 更新时间:2023-12-02 05:54:00 28 4
gpt4 key购买 nike

我正在使用

  • coverlet.msbuild v3.2.0
  • coverlet.collector v3.2.0

dotnet sdk v6.0.402

当我在 powershell 中运行此测试命令时(在此之前运行恢复和构建)

dotnet test --no-build --no-restore --collect:"XPlat Code Coverage" /p:Configuration=$Cfg /p:CollectCoverage=true /p:CoverletOutput=.\CodeCoverage\ --% /p:CoverletOutputFormat=\"cobertura,opencover\"

报告文件

  • coverage.cobertura.xml
  • coverage.opencover.xml

已创建,powershell 输出如下:

Test run for C:\Users\MyUser\repos\My.Project\Specs\bin\Release\net472\My.Project.Specs.dll (.NETFramework,Version=v4.7.2)
Microsoft (R) Test Execution Command Line Tool Version 17.3.1 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Attachments:
C:\Users\MyUser\repos\My.Project\Specs\TestResults\dbe8cb53-3ec5-4227-a231-3bfedf94694f\coverage.cobertura.xml
Passed! - Failed: 0, Passed: 14, Skipped: 0, Total: 14, Duration: 910 ms - My.Project.Specs.dll (net472)

Calculating coverage result...
Generating report '.\CodeCoverage\coverage.cobertura.xml'
Generating report '.\CodeCoverage\coverage.opencover.xml'

+----------------------+--------+--------+--------+
| Module | Line | Branch | Method |
+----------------------+--------+--------+--------+
| My.Project | 20.23% | 18.53% | 20.09% |
+----------------------+--------+--------+--------+

+---------+--------+--------+--------+
| | Line | Branch | Method |
+---------+--------+--------+--------+
| Total | 20.23% | 18.53% | 20.09% |
+---------+--------+--------+--------+
| Average | 20.23% | 18.53% | 20.09% |
+---------+--------+--------+--------+

我有这个 azure 管道任务:

- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
arguments: '--no-restore --no-build --collect:"XPlat Code Coverage" /p:Configuration=$(Build.Configuration) /p:CollectCoverage=true /p:CoverletOutput=$(Build.SourcesDirectory)\CodeCoverage --% /p:CoverletOutputFormat=\"cobertura,opencover\"'
publishTestResults: true

执行此命令:

C:\agent\_work\_tool\dotnet\dotnet.exe test --logger trx --results-directory C:\agent\_work\_temp --no-restore --no-build "--collect:XPlat Code Coverage" /p:Configuration=Release /p:CollectCoverage=true /p:CoverletOutput=C:\agent\_work\9\s\CodeCoverage --% "/p:CoverletOutputFormat=\cobertura,opencover\""

并且有这个输出

Test run for C:\agent\_work\9\s\My.Project.Specs\bin\Release\net472\My.Project.Specs.dll (.NETFramework,Version=v4.7.2)
Microsoft (R) Test Execution Command Line Tool Version 17.4.0 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
-> Loading plugin C:\agent\_work\9\s\My.Project.Specs\bin\Release\net472\LivingDoc.SpecFlowPlugin.dll
-> Loading plugin C:\agent\_work\9\s\My.Project.Specs\bin\Release\net472\TechTalk.SpecFlow.xUnit.SpecFlowPlugin.dll
-> Loading plugin C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\a4203b08-db42-449b-86d7-55cb48c54fc4\a4203b08-db42-449b-86d7-55cb48c54fc4\assembly\dl3\e501d05b\fee426f7_ddf4d801\My.Project.Specs.dll
-> Using specflow.json
-> LivingDocPlugin: Output generated in: C:\agent\_work\9\s\My.Project.Specs\bin\Release\net472\TestExecution.json
Results File: C:\agent\_work\_temp\BUILDMACHINE01$_BUILDMACHINE01_2022-11-10_09_25_37.trx

Passed! - Failed: 0, Passed: 14, Skipped: 0, Total: 14, Duration: 985 ms - My.Project.Specs.dll (net472)

Attachments:
C:\agent\_work\_temp\faa5dbb6-5931-43fe-880e-a37576815c1c\coverage.cobertura.xml
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://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.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 '1436028'.
TestResults To Publish 12, Test run id:1436028
Test results publishing 12, remaining: 0. Test run id: 1436028
Published Test Run : https://dev.azure.com/orgteamservices/My.Project/_TestManagement/Runs?runId=1436028&_a=runCharts
Async Command End: Publish test results
Finishing: Test

本地代理计算机上的预期目录中未生成任何报告。代理确实创建了这个C:\agent\_work\_temp\faa5dbb6-5931-43fe-880e-a37576815c1c\coverage.cobertura.xml

为什么它没有在预期目录中创建两个报告?

最佳答案

问题:

Visual Studio 构建工具 17.4.0 起,传递给 coverlet 的任何参数 (/p:) 都会被忽略。

解决方法:

指定 publishTestResults: true 作为 DotNetCoreCLI@2 任务的输入参数(或根本没有 publishTestResults 输入)会导致添加以下参数:--记录器 trx --results-directory $(Agent.TempDirectory)。这是normal behaviour顺便说一句。

这反过来会导致覆盖结果被放置在代理临时目录中,因为覆盖物参数被忽略。

因此将 publishTestResults 设置为 false

添加您自己现在省略的参数:--logger trx --results-directory CodeCoverage

通过文件或添加以下运行设置参数来传递任何其他runsettings:--DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover,cobertura

这应该可以暂时缓解这个问题。

这就是我的整个 yml 任务的样子:

- task: DotNetCoreCLI@2
displayName: 'Run acceptance tests'
inputs:
command: 'test'
projects: './src/Service.Requirements/Service.Requirements.csproj'
workingDirectory: './src/Service.Requirements'
publishTestResults: false
arguments: '--logger trx --results-directory CodeCoverage --configuration $(buildConfiguration) --no-build --collect "XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=opencover DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Exclude=[Service.Data]*'

关于azure - coverlet 不会在 azure devops 中创建报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74386402/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com