【问题标题】:Azure Pipelines - Where is the CodeCoverage generated by VSTest@2?Azure Pipelines - VSTest@2 生成的 CodeCoverage 在哪里?
【发布时间】:2019-12-02 07:17:25
【问题描述】:

我已经尝试了数百次,但我仍然无法找到在 VSTest 任务中生成的 codeCoverage 文件。

见以下代码。

我只是想将代码覆盖率报告发布到管道。

请帮忙!

代码覆盖率文件在哪里?

如果你不想浪费时间写一些答案,或者给我一些链接。

非常感谢!

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
  - master

jobs:
  - job: devbuild
    pool:
      name: 'Self Hosted VS2017'

    variables:
      solution: '**/*.sln'

    steps:
      - task: NuGetToolInstaller@0

      - task: NuGetCommand@2
        inputs:
          restoreSolution: '$(solution)'

      - task: VSBuild@1
        inputs:
          solution: '$(solution)'
          msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:Configuration=Debug /p:Platform="Any CPU" /p:OutDir=".\output\dev"'
          clean: true

      - task: VisualStudioTestPlatformInstaller@1
        inputs:
          packageFeedSelector: 'nugetOrg'
          versionSelector: 'latestPreRelease'

      - task: VSTest@2
        inputs:
          testSelector: 'testAssemblies'
          testAssemblyVer2: |
            **\dev\*.Tests.dll
          searchFolder: '$(System.DefaultWorkingDirectory)'
****************************************************************************
************THIS GUY  =>****************************************************
          codeCoverageEnabled: true
**********************<=****************************************************
****************************************************************************
          distributionBatchType: 'basedOnAssembly'
          dontDistribute: false
          publishRunAttachments: true

      - task: PublishCodeCoverageResults@1
        inputs:
          codeCoverageTool: 'cobertura'
          summaryFileLocation: '**/coverage.xml'
          reportDirectory: '**/coveragereport'
          failIfCoverageEmpty: true

【问题讨论】:

  • 在日志中找到覆盖文件了吗?
  • 嗨@starianchen-MSFT,不幸的是,不,我没有。我想这是由于 Visual Studio。虽然我使用 Visual Studio Professional 版本作为自托管代理,但此版本中没有生成代码覆盖率。
  • 代码覆盖率仅在 Visual Studio Enterprise 中可用 visualstudio.microsoft.com/vs/compare

标签: yaml code-coverage azure-pipelines vstest


【解决方案1】:

设置system.debug变量为true,然后进行队列构建,即可找到覆盖文件的全路径(在日志中搜索覆盖)

默认情况下,覆盖文件的名称是xx.coverage

【讨论】:

    【解决方案2】:

    这是我必须做的,以解决 Azure 对 vstest 结果所做的“良好”处理。

    首先,运行 vstest.console,这样 azure 就不会尝试自行发布测试结果,而是让您控制正在发生的事情。

    然后,使用 powershell 将 *.coverage 重命名为已知文件。

    这是我获得 .coverage 路径的唯一方法,以便以一种体面的方式将我的覆盖率导出到管道中(我的结果来自运行 c++ 和 c# 的 vstest,而 azure 不能很好地处理)。

    谢谢。

    【讨论】:

      【解决方案3】:

      尝试添加resultsFolder参数来控制文件位置

      # Ejecucion de los Test
      - task: VSTest@2
        displayName: 'Ejecucion de los Test'
        inputs:
          testSelector: 'testAssemblies' # Options: testAssemblies, testPlan, testRun
          testAssemblyVer2: | # Required when testSelector == TestAssemblies
            **\*.Test.dll
          searchFolder: '$(Build.SourcesDirectory)\Test' 
          vsTestVersion: '15.0'
          platform: 'x86' # Optional
          codeCoverageEnabled: true
          resultsFolder: '$(build.ArtifactStagingDirectory)\Test\Results'
      

      【讨论】:

        猜你喜欢
        • 2022-07-06
        • 2012-11-20
        • 2021-01-11
        • 2022-07-22
        • 1970-01-01
        • 2021-02-06
        • 2021-01-05
        • 1970-01-01
        • 2022-06-17
        相关资源
        最近更新 更多