由于使用GoMonkey Patch后导致GoConvey命令不能正常运行测试用例解决方案
出错提示
runtime error: invalid memory address or nil pointer dereference
原因
由于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
- 成功运行测试用例
彻底解决方案
需要向GoConvey作者提PR/ISSUE,使GoConvey支持go test 命令参数
转载请注明:MitNick » 由于使用GoMonkey Patch后导致GoConvey命令不能正常运行测试用例解决方案