Reputation: 1537
I created one sample go project and created a unit test cases for the same (In Linux environment, go1.3 version)
When i ran go test
the output would be
PASS
ok supported_db 0.201s
And i tried to perform code coverage for whole application by using go test -cover
command it shows
go tool: no such tool "cover"; to install:
go get code.google.com/p/go.tools/cmd/cover
Also i checked the coverage while running a specific test case by running go test -cover CouchDB_test.go
command it shows
ok command-line-arguments 0.158s coverage: 0.0% of statements
please help me to run code coverage in golang.
Upvotes: 13
Views: 13441
Reputation: 1324248
Try first:
go test -coverprofile=coverage.out
I then run, to see the result:
go tool cover -html=coverage.out
If the 1.3 version was installed through an upgrade of 1.1, 1.2, ..., you can try, as in issue 110:
I solved this by completely removing $GOPATH/src/code.google.com/p/go.tools and install cover again:
go get golang.org/x/tools/cmd/cover
Upvotes: 18
Reputation: 10143
Just add -coverpkg=./...
option if tests are in sub folders:
go test ./... -v -coverpkg=./...
Upvotes: 41