当我尝试以下
时go test -coverprofile=coverage.out
我得到了这个coverage.out:
mode: set
_/Users/gert/Desktop/httx/auth.go:10.66,11.54 1 0
_/Users/gert/Desktop/httx/auth.go:11.54,13.89 2 0
_/Users/gert/Desktop/httx/auth.go:17.3,17.11 1 0
_/Users/gert/Desktop/httx/auth.go:13.89,16.4 2 0
_/Users/gert/Desktop/httx/auth.go:22.42,25.2 2 0
...
但是当我做的时候
go tool cover -func=coverage.out
coverage.out似乎没有正确格式化?
cover: can't find "auth.go": cannot find package "_/Users/gert/Desktop/httx/" in any of:
/usr/local/Cellar/go/1.7.1/libexec/src/_/Users/gert/Desktop/httx (from $GOROOT)
/Users/gert/go/src/_/Users/gert/Desktop/httx (from $GOPATH)
编辑:请注意go test -cover
有效。
PASS
coverage: 29.7% of statements
ok _/Users/gert/Desktop/httx 0.015s
答案 0 :(得分:6)
您的评论包/Users/gert/Desktop/httx/
超出$GOPATH
/Users/gert/go
。将httx
包移到$GOPATH
下的某个位置,它会正常工作。您可以将其移至/Users/gert/go/src/httx
或类似/Users/gert/go/src/github.com/your-github-name/httx
(假设您使用GitHub)。
答案 1 :(得分:2)