gomock学习

88 篇文章 0 订阅

https://studygolang.com/articles/10124

安装

go get github.com/golang/mock/gomock

编译mockgen

cd $GOPATH/src/github.com/golang/mock/mockgen
go build

会在$GOPATH/src/github.com/golang/mock/mockgen下生成一个mocken可执行程序,Windows为mkcogen.exe,copy这个mockgen.exe到$GOPATH/bin

mv mockgen $GOPATH/bin

验证mockgen是否安装成功

mockgen

出现以上信息说明安装成功。如果出现 

-bash: mockgen: command not found

则表示安装失败,检查go path设置是否正确。

 

获取gomock文档

go doc github.com/golang/mock/gomock

gomock在线文档

https://godoc.org/github.com/golang/mock/gomock

mockgen指令参数

https://github.com/golang/mock#running-mockgen

-source :A file containing interfaces to be mocked.

-destination :A file to which to write the resulting source code. If you don't set this, the code is printed to standard output.

-package :The package to use for the resulting mock class source code. If you don't set this, the package name is mock_ concatenated with the package of the input file.

-imports :A list of explicit imports that should be used in the resulting source code, specified as a comma-separated list of elements of the form foo=bar/baz, where bar/baz is the package being imported and foo is the identifier to use for the package in the generated source code.

-aux_files: A list of additional files that should be consulted to resolve e.g. embedded interfaces defined in a different file. This is specified as a comma-separated list of elements of the form foo=bar/baz.go, where bar/baz.go is the source file and foo is the package name of that file used by the -source file.

-build_flags: (reflect mode only) Flags passed verbatim to go build.

-mock_names: A list of custom names for generated mocks. This is specified as a comma-separated list of elements of the form Repository=MockSensorRepository,Endpoint=MockSensorEndpoint, where Repository is the interface name and MockSensorRepository is the desired mock name (mock factory method and mock recorder will be named after the mock). If one of the interfaces has no custom name specified, then default naming convention will be used.


-copyright_file: Copyright file used to add copyright header to the resulting source code.

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值