【问题标题】:coverlet does not create report in azure devopsCoverlet 不会在 azure devops 中创建报告
【发布时间】:2022-11-12 02:15:44
【问题描述】:

我在用

  • 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% |
+---------+--------+--------+--------+

我有这个天蓝色管道任务:

- 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

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

【问题讨论】:

  • 我们有同样的问题。虽然我们还没有 --collect "XPlat Code Coverage" 参数。但是在我们将构建工具更新到最新版本 17.4 之前,它也可以正常工作。但是由于我们构建服务器上构建工具的更新,它不再生成覆盖文件。所以我想他们也更新了 Azure 的构建工具,因为新的 .net 7 版本发布了。
  • 我刚刚恢复到以前的构建工具版本 17.3.6。现在它又开始工作了。所以肯定与升级有关。

标签: azure powershell unit-testing code-coverage coverlet


【解决方案1】:

好的,找到了解决方案。

我创建了一个coverlet.runsettings 文件

<?xml version="1.0" encoding="utf-8" ?>
<RunSettings>
  <RunConfiguration>
    <ResultsDirectory>./CodeCoverage/</ResultsDirectory>
  </RunConfiguration>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="XPlat code coverage">
        <Configuration>
          <Format>cobertura,opencover</Format>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

并像这样改变了任务

diff --git a/azure-pipelines.yml b/azure-pipelines.yml
-            sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/CodeCoverage/coverage.opencover.xml
+            sonar.cs.opencover.reportsPaths=$(Agent.TempDirectory)/**/coverage.opencover.xml

-          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"
+          arguments: --no-restore --no-build --collect:"XPlat Code Coverage" --settings ./My.Project.Specs/coverlet.runsettings /p:Configuration=$(Build.Configuration) /p:CollectCoverage=true  /p:CoverletOutput=$(Agent.TempDirectory) --% /p:CoverletOutputFormat="cobertura,opencover"

-          summaryFileLocation: '$(Build.SourcesDirectory)/CodeCoverage/coverage.cobertura.xml'
+          summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'

我使用代理临时目录和全局模式指定报告文件的路径。

此任务现在创建此输出(缩写):

C:gent_work_tooldotnetdotnet.exe test --logger trx --results-directory C:gent_work_temp --no-restore --no-build "--collect:XPlat Code Coverage" --settings ./My.Project.Specs/coverlet.runsettings /p:Configuration=Release /p:CollectCoverage=true /p:CoverletOutput=C:gent_work_temp --% "/p:CoverletOutputFormat=cobertura,opencover""
Test run for C:gent_work9sMy.Project.SpecsinRelease
et472My.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:gent_work9sMy.Project.SpecsinRelease
et472LivingDoc.SpecFlowPlugin.dll
-> Loading plugin C:gent_work9sMy.Project.SpecsinRelease
et472TechTalk.SpecFlow.xUnit.SpecFlowPlugin.dll
-> Loading plugin C:WindowsServiceProfilesNetworkServiceAppDataLocalTempa03db93-d250-4d1a-acfc-4ec086feac88a03db93-d250-4d1a-acfc-4ec086feac88ssemblydl3a2f2724d56f5937_94f5d801My.Project.Specs.dll
-> Using specflow.json
-> LivingDocPlugin: Output generated in: C:gent_work9sMy.Project.SpecsinRelease
et472TestExecution.json
Results File: C:gent_work_tempBUILDMACHINE01$_BUILDMACHINE01_2022-11-11_07_10_08.trx

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

Attachments:
  C:gent_work_tempc68cb66e-3fd4-498d-b3e3-218ed75f68a8coverage.cobertura.xml
  C:gent_work_tempc68cb66e-3fd4-498d-b3e3-218ed75f68a8coverage.opencover.xml

它仍然会忽略我提供的所有目录,但会在我可以访问它们的临时目录中创建两个报告。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-13
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-03
    • 1970-01-01
    相关资源
    最近更新 更多