Skip to content

Instantly share code, notes, and snippets.

@hermannolafs
Created February 12, 2021 12:11
Show Gist options
  • Save hermannolafs/a3314f7f950701471a7b30e4dd6da834 to your computer and use it in GitHub Desktop.
Save hermannolafs/a3314f7f950701471a7b30e4dd6da834 to your computer and use it in GitHub Desktop.
Azure Pipelines Golang Test with test resulsts and code coverage artifacts
- job: jobRunTestsuites
container: golang:1.15-buster
displayName: "Run Testsuites"
steps:
- task: Bash@3
displayName: "Go | Test and handle test cov"
inputs:
targetType: inline
workingDirectory: "$(System.DefaultWorkingDirectory)"
script: |
go get github.com/axw/gocov/gocov
go get github.com/matm/gocov-html
go get gotest.tools/gotestsum
go get github.com/boumenot/gocover-cobertura # This is a fork in an otherwise inactive repo
# Run tests with gotestsum to generate coverate & JUnit test report
gotestsum --junitfile tests.xml -- -coverprofile=coverage.txt ./...
# Generate Cobertura xml coverage file from Go coverage file
gocover-cobertura < coverage.txt > coverage.xml
# HTML for coverage report
mkdir report
gocov convert coverage.txt | gocov-html > report/index.html
- task: PublishTestResults@2
inputs:
testResultsFormat: JUnit
testResultsFiles: $(System.DefaultWorkingDirectory)/tests.xml
failTaskOnFailedTests: true # This is required for the job/stage to fail with failing tests
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
pathToSources: "$(System.DefaultWorkingDirectory)/coverage.xml"
summaryFileLocation: $(System.DefaultWorkingDirectory)/coverage.xml
reportDirectory: $(System.DefaultWorkingDirectory)/report
@hermannolafs
Copy link
Author

If tests fail no results or coverage is posted. Someone wiser that me please tell me if that is expected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment