...
The same coverage reported from the command line:
How to Generate Code Coverage Reports for Golang Applications
This document covers how to generate HTML Code Coverage Reports for Golang Applications.
Code Block |
---|
language | bash |
---|
title | Generate and run a test executable which calls your main() |
---|
linenumbers | true |
---|
|
go test -c -covermode=count -coverpkg ./...
./sms.test -test.run "^TestMain$" -test.coverprofile=coverage.cov |
Code Block |
---|
language | bash |
---|
title | Run your Unit tests for their coverage |
---|
linenumbers | true |
---|
|
go test -test.covermode=count -test.coverprofile=unit.out ./... |
Code Block |
---|
language | bash |
---|
title | Merge coverage Reports |
---|
linenumbers | true |
---|
|
go get github.com/wadey/gocovmerge
gocovmerge unit.out coverage.cov > all.out |
Code Block |
---|
language | bash |
---|
title | Generate Reports |
---|
linenumbers | true |
---|
|
# HTML Report File
go tool cover -html all.out -o coverage.html
# Function Coverage Report
go tool cover -func all.out |