9

I have tried hundreds of times but I am still unable to find that codeCoverage file generated in VSTest task.

See the following code.

I simply want to publish the Code Coverage report to the pipeline.

Help, please!

Where is that code coverage file?

Or give me some links if you don't want to waste time writing some answers.

Many thanks!

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.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

I want this, image grabbed from internet

ske
  • 4,694
  • 3
  • 23
  • 35

4 Answers4

14

This is what worked for me. I had to tell vstest to output in Cobertura format, then publish coverage results manually:

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*Tests.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    resultsFolder: '$(build.ArtifactStagingDirectory)/Test/Results'
    otherConsoleOptions: '/collect:"Code Coverage;Format=Cobertura"'  # <<<< this is the important bit
    codeCoverageEnabled: True

# vv Then add publish coverage manually vv
- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: 'Cobertura'
    summaryFileLocation: '$(build.ArtifactStagingDirectory)/Test/Results/**/*.xml'

Then I got the nice HTML output in the coverage tab in DevOps

Henry Ing-Simmons
  • 1,362
  • 5
  • 18
  • 25
4

Try to add resultsFolder parameter to control file location

# 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'
user2480745
  • 111
  • 1
  • 2
3

Set system.debug variable to true, then queue build, you can find the whole path of coverage files (search coverage in log)

By default, the coverage file's name is xx.coverage.

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
1

This is what I had to do to workaround the "nice" handling that Azure's does with the results of the vstest.

First, run vstest.console, this way azure doesn't try to publish the test results by itself and gives you control on what's going on.

Then, used a powershell to rename the *.coverage into a known file.

That's what the only way I got to have my .coverage path in order to do a decent way of exporting my coverage into the pipeline (my results are from vstest running c++ and c#, which azure doesn't handle well).

Thanks.

ldcl289
  • 41
  • 1
  • 8