Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setup code coverage for Go in Azure DevOps

It is not clear for me how code coverage works in Azure DevOps for my Golang project. My expertation is to see something like this:

enter image description here

Missing Code Coverage

I'm confused, because I see this hint "Setup code coverage":

enter image description here

But in the tab "Code Coverage" is a generated html report:

enter image description here

Warning in Task "Publish code coverage results"

I got this warning in the task "Publish code coverage results"

##[warning]Ignoring coverage report directory with Html content as we are auto-generating Html content

But when I disable the html generation with disable.coverage.autogenerate: 'false' no report is display under the tab "Code Coverage", only the message "Code coverage report cannot be rendered as report HTML was not found. Please verify that "Report Directory" containing an HTML report was specified when publishing code coverage."

Azure Pipeline

This is my pipeline:

trigger: 
 - master

pool:
   vmImage: 'ubuntu-latest'

variables:
  GOBIN:  '$(GOPATH)/bin'
  GOPATH: '$(system.defaultWorkingDirectory)/gopath'
  disable.coverage.autogenerate: 'false'

steps: 

- script: |
    echo '##vso[task.prependpath]$(GOBIN)'
    echo '##vso[task.prependpath]$(GOROOT)/bin'

- task: GoTool@0
  inputs:
    version: '1.14.2'
- task: Go@0
  inputs:
    command: 'get'
    arguments: '-d ./...'
    workingDirectory: '$(System.DefaultWorkingDirectory)'

- script: |
    go get github.com/jstemmer/go-junit-report
    go get github.com/axw/gocov/gocov
    go get github.com/AlekSi/gocov-xml
    go test -v -coverprofile=coverage.txt -covermode count ./... 2>&1 | go-junit-report > report.xml
    gocov convert coverage.txt > coverage.json
    gocov-xml < coverage.json > coverage.xml
    mkdir coverage
  workingDirectory: '$(System.DefaultWorkingDirectory)'
  displayName: 'Run unit test'

- task: PublishTestResults@2
  inputs:
    testRunner: JUnit
    testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml

- task: PublishCodeCoverageResults@1
  inputs:
    codeCoverageTool: Cobertura 
    pathToSources: '$(System.DefaultWorkingDirectory)'
    summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml
    reportDirectory: $(System.DefaultWorkingDirectory)/**/coverage
    failIfCoverageEmpty: true

Full log: https://gist.githubusercontent.com/dhcgn/682dd6027d8d0703cb4dc6d5ae2fbead/raw/9d2bb96d1d8a0721335d56a121a5eed254ac014f/pipeline.log

like image 473
hdev Avatar asked Feb 16 '26 18:02

hdev


1 Answers

The code coverage report you expect to see on the build summary is the old build pipeline UI page.

Now Azure devops services has implemented the new multi-stage pipelines UI page. Code coverage report is moved to the Code Coverage tab as what you see now.

The build Summary page you expect to see in above screenshot is no longer available, for the this feature toggle which allows to switch back to the old build pipeline UI page has been removed. See here.

However, you can still see the old pipeline UI page in Azure DevOps Server 2019/TFS 2018 /TFS 2017.

like image 140
Levi Lu-MSFT Avatar answered Feb 18 '26 17:02

Levi Lu-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!