Reputation: 2752
I am trying to configure VSTS Build to run our Integration tests and generate the code coverage HTML report. I am using Coverlet and ReportGenerator plugin to accomplish this. This is how I have my build configured right now:
pool:
name: Hosted VS2017
demands:
- msbuild
- visualstudio
steps:
- task: NuGetToolInstaller@0
displayName: 'Use NuGet 4.7.1'
inputs:
versionSpec: 4.7.1
- task: NuGetCommand@2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
- task: VSBuild@1
displayName: 'Build solution'
inputs:
solution: '$(Parameters.solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\\"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
- task: DotNetCoreCLI@2
displayName: 'Run Integration Tests'
inputs:
command: test
arguments: '-c $(BuildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)\TestResults\Coverage\ --no-build'
- task: Palmmedia.reportgenerator.reportgenerator-build-release-task.reportgenerator@1
displayName: ReportGenerator
inputs:
reports: '$(Build.SourcesDirectory)\TestResults\Coverage\coverage.cobertura.xml'
targetdir: '$(Build.SourcesDirectory)\coveragereport'
- task: PublishCodeCoverageResults@1
displayName: 'Publish code coverage results'
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(Build.SourcesDirectory)\coveragereport\Cobertura.xml'
reportDirectory: '$(build.sourcesdirectory)\src\target\reports\coverage'
- task: PublishSymbols@1
displayName: 'Publish symbols path'
inputs:
SearchPattern: '**\bin\**\*.pdb'
continueOnError: true
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
ArtifactName: '$(Parameters.ArtifactName)'
I am not sure where I am making the mistake, but the build seems to complete without any errors and still I do not see anything in the code coverage tab. Can you please explain what am I missing?
Upvotes: 1
Views: 911
Reputation: 2752
Ok I was finally able to resolve the issues with the help of this post
Turns out if you read very carefully then the "Target Directory" of the Report Generator step needs to match the "Report Directory" of the Publish CodeCoverage Results task. If you look at my original question they were different because my understanding was incorrect. Once I fixed the paths, the code coverage started showing in the build code coverage tab. Hope it helps someone facing the same issue.
Upvotes: 1