How to Generate Code Coverage Reports for Golang Applications
This document covers how to generate HTML Code Coverage Reports for Golang Applications.
Generate and run a test executable which calls your main()
1 2 | go test -c -covermode=count -coverpkg ./...
. /sms . test - test .run "^TestMain$" - test .coverprofile=coverage.cov
|
Run your Unit tests for their coverage
1 | go test - test .covermode=count - test .coverprofile=unit.out ./...
|
Merge coverage Reports
1 2 | go get github.com /wadey/gocovmerge
gocovmerge unit.out coverage.cov > all.out
|
Generate Reports
1 2 3 4 5 |
go tool cover -html all.out -o coverage.html
go tool cover -func all.out
|