Golang - codecoverage always shows coverage: 0.0% of claims

I created one sample go project and created unit test tags for it (on Linux environment, go1.3 version)

When I run go test

, the output will be

PASS
ok supported_db 0.201s

And I tried to do code coverage for the whole application using the command go test -cover

which shows

go tool: there is no such tool "cover"; to install:
go get code.google.com/p/go.tools/cmd/cover

Also I checked the coverage when running a specific test case by running the command go test -cover CouchDB_test.go

which displays

ok command line arguments 0.158s coverage: 0.0% statements

please help me to run code coverage in golang.

+4


source to share


2 answers


Try first:

go test -coverprofile=coverage.out

      

Then I ran to see the result:

go tool cover -html=coverage.out

      



If version 1.3 was installed with update 1.1, 1.2, ..., you can try like in issue 110 :

I solved this by completely removing $ GOPATH / src / code.google.com / p / go.tools and reinstalling the cover again:

go get code.google.com/p/go.tools/cmd/cover

      

+5


source


It helped me

Just add -coverpkg=./...

if tests are in subfolders:



go test ./... -v -coverpkg=./...

      

0


source







All Articles