如何在Go GAE应用程序上可视化代码覆盖率信息?

huangapple go评论72阅读模式
英文:

How to visualize code coverage information on Go GAE apps?

问题

我正在使用最新的Go GAE SDK开发一个服务器。我在每次更改后运行测试:

goapp test -test.v=true

我使用-cover来记录覆盖率,如goapp help testflag所述:

goapp test -cover -test.v=true -test.coverprofile=c.out
[..]
覆盖率:53.8%的语句
ok _/var/lib/jenkins/jobs/loyalty/workspace 30.464s

这个命令成功完成并打印出测试覆盖率的百分比。然而,尝试可视化结果失败

goapp tool cover -html=c.out
cover: 找不到"app.go":无法在以下任何位置找到包"/home/ingo/git/loyalty/":
/home/ingo/Downloads/go_appengine_sdk_linux_amd64-1.9.10/go_appengine/goroot/src/pkg/
/home/ingo/git/loyalty (from $GOROOT)
/home/ingo/git/loyalty/src/_/home/ingo/git/loyalty (from $GOPATH)

Go的覆盖工具只适用于非GAE应用程序吗?我需要以不同的方式打包我的应用程序才能可视化覆盖结果吗?

我之前在golang-nuts上提问过,但没有成功解决。

英文:

I am developing a server with the latest Go GAE SDK. I am running tests after every change:

goapp test -test.v=true

I am using -cover to record coverage as described by goapp help testflag:

goapp test -cover -test.v=true -test.coverprofile=c.out
[..]
coverage: 53.8% of statements
ok  	_/var/lib/jenkins/jobs/loyalty/workspace	30.464s

This completes successfully and prints the percentage of lines covered by tests. However, attempting to visualize the results fails:

goapp tool cover -html=c.out
cover: can't find "app.go": cannot find package "_/home/ingo/git/loyalty/" in any of:
/home/ingo/Downloads/go_appengine_sdk_linux_amd64-1.9.10/go_appengine/goroot/src/pkg/_/home/ingo/git/loyalty (from $GOROOT)
/home/ingo/git/loyalty/src/_/home/ingo/git/loyalty (from $GOPATH)

Does Go's cover tool only work on non-GAE apps? Do I have to package my app differently in order to visualize the coverage results?

I unsuccessfully asked this on golang-nuts before.

答案1

得分: 5

有一个与此相关的未解决问题。作为一个临时解决方法,我在收集和可视化覆盖率结果之间运行了sed命令。

goapp test -cover -test.v=true -test.coverprofile=c.out
sed -i -e "s#.*/\(.*\.go\)#\./\#" c.out
goapp tool cover -html c.out -o coverage.html
英文:

There is an open issue related to it. As a temporary workaround, I am running sed in between collecting and visualizing the coverage results.

goapp test -cover -test.v=true -test.coverprofile=c.out
sed -i -e "s#.*/\(.*\.go\)#\./\#" c.out
goapp tool cover -html c.out -o coverage.html

huangapple
  • 本文由 发表于 2014年10月26日 02:31:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/26565794.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定