I have written my Unit Test Specflow. Iam not able to implement code coverage using Azure pipeline . Can someone help me?

Viewed 205

In my web api project I have written unit test in Specflow (MStest). FYI: all my test cases pass.

This is the build pipeline:

- task: DotNetCoreCLI@2
  displayName: 'Install ReportGenerator'
  inputs:
    command: custom
    custom: tool
    arguments: 'install --global dotnet-reportgenerator-globaltool
- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '**/project/webApi/**/*Tests.csproj'
    publishTestResults: false
    arguments: '--configuration $(buildConfiguration) /p:Collect="XPlat Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/ "/p:MergeWith=../TestResults/coverlet.json"'


- task: PublishCodeCoverageResults@1
  displayName: CodeCoverage
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(Build.SourcesDirectory)/**/Coverage/*.xml'

- task: reportgenerator@4
  inputs:
    reports: '$(Build.SourcesDirectory)/**/*.cobertura.xml'
    targetdir: '$(Build.SourcesDirectory)/CoverageResults'

The xml file which has to be generated is not generated. When tried to publish the code using Coberta

Error: the report file pattern 'D:\a\1\s/**/*.cobertura.xml' is invalid. No matching files found.
No report files specified

Here's a screenshot for illustration:

I am getting this error

1 Answers

You don't need reportgenerator with the newest dotnet cli.

And pleae try with this configuration:

# You just added coverlet.collector to use 'XPlat Code Coverage'
- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage"'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage'
  inputs:
    codeCoverageTool: Cobertura
    summaryFileLocation: '$(Agent.TempDirectory)/**/coverage.cobertura.xml'

Related