https://github.com/uber-go/mock
Install mockgen:
zzh@ZZHPC:/zdata/Github/zimplebank$ go install go.uber.org/mock/mockgen@latest go: downloading go.uber.org/mock v0.3.0 go: downloading golang.org/x/mod v0.11.0 go: downloading golang.org/x/tools v0.2.0 go: downloading golang.org/x/sys v0.1.0
zzh@ZZHPC:~$ mockgen -h mockgen has two modes of operation: source and reflect. Source mode generates mock interfaces from a source file. It is enabled by using the -source flag. Other flags that may be useful in this mode are -imports and -aux_files. Example: mockgen -source=foo.go [other options] Reflect mode generates mock interfaces by building a program that uses reflection to understand interfaces. It is enabled by passing two non-flag arguments: an import path, and a comma-separated list of symbols. Example: mockgen database/sql/driver Conn,Driver
zzh@ZZHPC:/zdata/Github/zimplebank$ mockgen -destination db/mock/store.go github.com/ZhangZhihuiAAA/zimplebank/db/sqlc Store prog.go:12:2: no required module provides package go.uber.org/mock/mockgen/model; to add it: go get go.uber.org/mock/mockgen/model prog.go:12:2: no required module provides package go.uber.org/mock/mockgen/model; to add it: go get go.uber.org/mock/mockgen/model prog.go:14:2: no required module provides package github.com/ZhangZhihuiAAA/zimplebank/db/sqlc: go.mod file not found in current directory or any parent directory; see 'go help modules' prog.go:12:2: no required module provides package go.uber.org/mock/mockgen/model: go.mod file not found in current directory or any parent directory; see 'go help modules' 2023/12/04 18:16:33 Loading input failed: exit status 1
zzh@ZZHPC:/zdata/Github/zimplebank$ go get go.uber.org/mock/mockgen/model go: added go.uber.org/mock v0.3.0 zzh@ZZHPC:/zdata/Github/zimplebank$ mockgen -package mockdb -destination db/mock/store.go github.com/ZhangZhihuiAAA/zimplebank/db/sqlc Store zzh@ZZHPC:/zdata/Github/zimplebank$