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

个人博客原文地址:http://www.lampnick.com/php/740

由于使用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" 

临时解决方案

  • 安装GoConvey
go get github.com/smartystreets/goconvey
  • 修改源文件
/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}
  • 重新安装GoConvey
go install github.com/smartystreets/goconvey
  • 运行
cd <project path>
$GOPATH/bin/goconvey
  • 成功运行测试用例 image

彻底解决方案

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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值