一旦工作,那就要努力的干,聪明的干,快速的干——用省下来的时间干自己喜欢干的事情。!

由于使用GoMonkey Patch后导致GoConvey命令不能正常运行测试用例解决方案

go lampnick 3829℃ 0评论

由于使用GoMonkey Patch后导致GoConvey命令不能正常运行测试用例解决方案

出错提示

runtime error: invalid memory address or nil pointer dereference

image

原因

由于GoMonkey Patch后需要关闭编译器对代码自动优化功能才能正常运行,但是GoConvey命令并不支持传入go test命令参数,所以导致GoConvey不能正常使用
go test -gcflags "all=-N -l" 

临时解决方案

  1. 安装GoConvey
go get github.com/smartystreets/goconvey
  1. 修改源文件
/Users/nick/gocode/src/github.com/smartystreets/goconvey/web/server/system/shell.go:56
修改为:
return NewCommand(directory, gobin, "test", "-gcflags", "all=-N -l", tagsArg)
/Users/nick/gocode/src/github.com/smartystreets/goconvey/web/server/system/shell.go:68
修改为:
arguments := []string{"test", "-gcflags", "all=-N -l", "-v", "-coverprofile=" + reportPath, tagsArg}
/Users/nick/gocode/src/github.com/smartystreets/goconvey/web/server/system/shell.go:106
修改为:
arguments := []string{"test", "-gcflags", "all=-N -l", "-v", tagsArg}
  1. 重新安装GoConvey
go install github.com/smartystreets/goconvey
  1. 运行
cd <project path>
$GOPATH/bin/goconvey
  1. 成功运行测试用例 image

彻底解决方案

需要向GoConvey作者提PR/ISSUE,使GoConvey支持go test 命令参数

转载请注明:MitNick » 由于使用GoMonkey Patch后导致GoConvey命令不能正常运行测试用例解决方案

喜欢 (3)or分享 (0)
头像
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址