Search code examples
reactjsazureazure-devopsazure-pipelinescobertura

How to set up a code coverage badge for an Azure private repository?


I have a ReactJS project on Azure, and I'm publishing code coverage with Cobertura.

I've seen tools like badge.io you can use for getting a badge, but it seems it can only provide badges for publich repositories. How can I get a badge in my readme.md in this private Azure hosted repository?

azure-pipelines.yml:

- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: 'cobertura'
    summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage/cobertura-coverage.xml'

Solution

  • If you donot have coverage reports files you need to add task reportgenerator(install this task to your organization if not installed) before publishcodecoverageresults task. Please check below example

    - task: reportgenerator@4
      displayName: ReportGenerator
      inputs:
        reports: '$(System.DefaultWorkingDirectory)\TestCoverage.xml'
        targetdir: '$(Build.SourcesDirectory)\TestResults\Coverage\Reports'
        sourcedirs: '$(Build.SourcesDirectory)'
        verbosity: Verbose
    
    
    - task: PublishCodeCoverageResults@1
      inputs:
        codeCoverageTool: 'cobertura'
        summaryFileLocation: '$(System.DefaultWorkingDirectory)\TestCoverage.xml'
        pathToSources: '$(Build.SourcesDirectory)'
        reportDirectory: '$(Build.SourcesDirectory)\TestResults\Coverage\Reports'
    

    What status you want to show for the badge?

    If you want to add build status badge to your readme in your repo. You can check here to add status badge to your repo for build status.

    enter image description here

    Update:

    Since There is no test coverage percentage badge in azure devops test results. You can install code coverage extensions, eg. code coverage protector or Code Coverage Widgets. Please follow below screenshot to browse marketplace and search for code coverage enter image description here

    When you installed the code coverage extensions from the marketplace. You can then Add a code coverage widgets to a dashboard.

    You can also submit a feature request(click suggest a feature and select Azure Devops) for test coverage percentage badge to Microsoft development team. Hope they will consider this and implement it in the future.