MOCKGEN(1)
π MOCKGEN(1) π
okay so bestie, gather round, we're talking about mockgen β a User Command that lives in your terminal and is genuinely so good at its job. Go devs, this one's for you π«Ά
β¨ NAME β¨
mockgen β generate source for mock class of a Go source π
πΈ DESCRIPTION πΈ
The mockgen command is used to generate source code for a mock class given a Go source file containing interfaces to be mocked. literally its whole personality. it reads interfaces, it writes mocks, it slays.
mockgen has two modes of operation: source and reflect. two vibes. pick one. iykyk.
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
-aux_files=""β (source mode) Comma-separatedpkg=pathpairs of auxiliary Go source files.-debug_parser=falseβ Print out parser results only. that's it, that's the whole thing π-destination=""β Output file; defaults to stdout. no file? cool, it just yells into your terminal.-exec_only=""β (reflect mode) If set, execute this reflection program.-imports=""β (source mode) Comma-separatedname=pathpairs of explicit imports to use.-package=""β Package of the generated code; defaults to the package of the input with a'mock_'prefix. cute little auto-nickname, love that for it β¨-prog_only=falseβ (reflect mode) Only generate the reflection program; write it to stdout.-self_package=""β If set, the package this mock will be part of.-source=""β (source mode) Input Go source file; enables source mode.
π¦ okay so. it says it again. π¦
bestie i need you to know this is not me being lazy β the manpage genuinely says all of this a second time, word for word. so here it is again, verbatim, because i keep every detail and i do not skip. periodt. π
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
-aux_files=""β (source mode) Comma-separatedpkg=pathpairs of auxiliary Go source files.-debug_parser=falseβ Print out parser results only.-destination=""β Output file; defaults to stdout.-exec_only=""β (reflect mode) If set, execute this reflection program.-imports=""β (source mode) Comma-separatedname=pathpairs of explicit imports to use.-package=""β Package of the generated code; defaults to the package of the input with a'mock_'prefix.-prog_only=falseβ (reflect mode) Only generate the reflection program; write it to stdout.-self_package=""β If set, the package this mock will be part of.-source=""β (source mode) Input Go source file; enables source mode.
and that's the whole page, bestie!! go forth and mock responsibly π
this edition is dated September 2015, and it's page MOCKGEN(1) of the manual β same title up top, same title down at the bottom, full circle moment π
later, legend πβ¨π¦
π¦ where this page comes from
- debian bookworm: mockgen 1.6.0-2+b6 Β· Apache-2.0
- debian trixie: mockgen 1.6.0-2+b17 Β· Apache-2.0
- ubuntu jammy: mockgen 1.6.0-1 Β· Apache-2.0
- ubuntu jammy: mockgen 1.6.0-1ubuntu0.1 Β· Apache-2.0
- ubuntu noble: mockgen 1.6.0-2build1 Β· Apache-2.0
- ubuntu noble: mockgen 1.6.0-2ubuntu0.24.04.3 Β· Apache-2.0
- ubuntu questing: mockgen 1.6.0-2build1
- ubuntu resolute: mockgen 1.6.0-2build2 Β· Apache-2.0
- ubuntu stonking: mockgen 1.6.0-3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms