Azure Pipelines - Where is the CodeCoverage generated by VSTest@2?
Asked Answered
G

4

10

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

Galacto answered 24/7, 2019 at 7:46 Comment(4)
Try this: stackoverflow.com/questions/56516073Kirkwood
Have you found the coverage file in log?Ardie
Hi @starianchen-MSFT, Unfortunately, No, I haven't. I guess it's due to the Visual Studio. While I use Visual Studio Professional version as the self-hosted agent, there is no Code Coverage generated in this version.Galacto
Code coverage just available in Visual Studio Enterprise visualstudio.microsoft.com/vs/compareArdie
A
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.

Ardie answered 24/7, 2019 at 11:4 Comment(1)
Where is system.debug ?!!?!?!?!?!?!?!?!?!?!?!?!!?!?!?! What is system.debug ?????? Who is system.debug ???Keesee
F
19

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

Finke answered 7/4, 2022 at 11:14 Comment(4)
What is "Cobertura", that's like Spanish.Keesee
Cobertura is a code coverage reporting tool used in Azure Devops and the VSTest task to generate the code coverage of the repository.Xochitlxp
Thank you so much for suggesting this answer. After a month of searching for solution, this answer helped resolve the issue in an hour. It was super helpful.Xochitlxp
@henry-ing-simmons This worked great using PublishCodeCoverageResults@1. Have you tried updating to PublishCodeCoverageResults@2 yet? I saw a warning in our pipeline and version 1 was deprecated and the recommendation is to switch to 2. It didn't work well so far.Panther
E
6

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'
Ebonyeboracum answered 27/6, 2020 at 7:24 Comment(0)
A
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.

Ardie answered 24/7, 2019 at 11:4 Comment(1)
Where is system.debug ?!!?!?!?!?!?!?!?!?!?!?!?!!?!?!?! What is system.debug ?????? Who is system.debug ???Keesee
B
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.

Breather answered 6/3, 2020 at 21:53 Comment(1)
Could you please the sample implementation for reference?Xochitlxp

© 2022 - 2024 — McMap. All rights reserved.