[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-5092":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":20,"defaultBranch":21,"hasWiki":19,"hasPages":20,"topics":22,"createdAt":9,"pushedAt":9,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":15,"starSnapshotCount":15,"syncStatus":26,"lastSyncTime":27,"discoverSource":28},5092,"mock","golang\u002Fmock","golang","GoMock is a mocking framework for the Go programming language.",null,"Go",9362,604,3,61,0,1,64.45,"Apache License 2.0",true,false,"main",[],"2026-06-12 04:00:24","# gomock\n\n**Update, June 2023**: _This repo and tool are no longer maintained.\nPlease see [go.uber.org\u002Fmock](https:\u002F\u002Fgithub.com\u002Fuber\u002Fmock) for a maintained fork instead._\n\n[![Build Status][ci-badge]][ci-runs] [![Go Reference][reference-badge]][reference]\n\ngomock is a mocking framework for the [Go programming language][golang]. It\nintegrates well with Go's built-in `testing` package, but can be used in other\ncontexts too.\n\n## Installation\n\nOnce you have [installed Go][golang-install], install the `mockgen` tool.\n\n**Note**: If you have not done so already be sure to add `$GOPATH\u002Fbin` to your\n`PATH`.\n\nTo get the latest released version use:\n\n### Go version \u003C 1.16\n\n```bash\nGO111MODULE=on go get github.com\u002Fgolang\u002Fmock\u002Fmockgen@v1.6.0\n```\n\n### Go 1.16+\n\n```bash\ngo install github.com\u002Fgolang\u002Fmock\u002Fmockgen@v1.6.0\n```\n\nIf you use `mockgen` in your CI pipeline, it may be more appropriate to fixate\non a specific mockgen version. You should try to keep the library in sync with\nthe version of mockgen used to generate your mocks.\n\n## Running mockgen\n\n`mockgen` has two modes of operation: source and reflect.\n\n### Source mode\n\nSource mode generates mock interfaces from a source file.\nIt is enabled by using the -source flag. Other flags that\nmay be useful in this mode are -imports and -aux_files.\n\nExample:\n\n```bash\nmockgen -source=foo.go [other options]\n```\n\n### Reflect mode\n\nReflect mode generates mock interfaces by building a program\nthat uses reflection to understand interfaces. It is enabled\nby passing two non-flag arguments: an import path, and a\ncomma-separated list of symbols.\n\nYou can use \".\" to refer to the current path's package.\n\nExample:\n\n```bash\nmockgen database\u002Fsql\u002Fdriver Conn,Driver\n\n# Convenient for `go:generate`.\nmockgen . Conn,Driver\n```\n\n### Flags\n\nThe `mockgen` command is used to generate source code for a mock\nclass given a Go source file containing interfaces to be mocked.\nIt supports the following flags:\n\n- `-source`: A file containing interfaces to be mocked.\n\n- `-destination`: A file to which to write the resulting source code. If you\n  don't set this, the code is printed to standard output.\n\n- `-package`: The package to use for the resulting mock class\n  source code. If you don't set this, the package name is `mock_` concatenated\n  with the package of the input file.\n\n- `-imports`: A list of explicit imports that should be used in the resulting\n  source code, specified as a comma-separated list of elements of the form\n  `foo=bar\u002Fbaz`, where `bar\u002Fbaz` is the package being imported and `foo` is\n  the identifier to use for the package in the generated source code.\n\n- `-aux_files`: A list of additional files that should be consulted to\n  resolve e.g. embedded interfaces defined in a different file. This is\n  specified as a comma-separated list of elements of the form\n  `foo=bar\u002Fbaz.go`, where `bar\u002Fbaz.go` is the source file and `foo` is the\n  package name of that file used by the -source file.\n\n- `-build_flags`: (reflect mode only) Flags passed verbatim to `go build`.\n\n- `-mock_names`: A list of custom names for generated mocks. This is specified\n  as a comma-separated list of elements of the form\n  `Repository=MockSensorRepository,Endpoint=MockSensorEndpoint`, where\n  `Repository` is the interface name and `MockSensorRepository` is the desired\n  mock name (mock factory method and mock recorder will be named after the mock).\n  If one of the interfaces has no custom name specified, then default naming\n  convention will be used.\n\n- `-self_package`: The full package import path for the generated code. The\n  purpose of this flag is to prevent import cycles in the generated code by\n  trying to include its own package. This can happen if the mock's package is\n  set to one of its inputs (usually the main one) and the output is stdio so\n  mockgen cannot detect the final output package. Setting this flag will then\n  tell mockgen which import to exclude.\n\n- `-copyright_file`: Copyright file used to add copyright header to the resulting source code.\n\n- `-debug_parser`: Print out parser results only.\n\n- `-exec_only`: (reflect mode) If set, execute this reflection program.\n\n- `-prog_only`: (reflect mode) Only generate the reflection program; write it to stdout and exit.\n\n- `-write_package_comment`: Writes package documentation comment (godoc) if true. (default true)\n\nFor an example of the use of `mockgen`, see the `sample\u002F` directory. In simple\ncases, you will need only the `-source` flag.\n\n## Building Mocks\n\n```go\ntype Foo interface {\n  Bar(x int) int\n}\n\nfunc SUT(f Foo) {\n \u002F\u002F ...\n}\n\n```\n\n```go\nfunc TestFoo(t *testing.T) {\n  ctrl := gomock.NewController(t)\n\n  \u002F\u002F Assert that Bar() is invoked.\n  defer ctrl.Finish()\n\n  m := NewMockFoo(ctrl)\n\n  \u002F\u002F Asserts that the first and only call to Bar() is passed 99.\n  \u002F\u002F Anything else will fail.\n  m.\n    EXPECT().\n    Bar(gomock.Eq(99)).\n    Return(101)\n\n  SUT(m)\n}\n```\n\nIf you are using a Go version of 1.14+, a mockgen version of 1.5.0+, and are\npassing a *testing.T into `gomock.NewController(t)` you no longer need to call\n`ctrl.Finish()` explicitly. It will be called for you automatically from a self\nregistered [Cleanup](https:\u002F\u002Fpkg.go.dev\u002Ftesting?tab=doc#T.Cleanup) function.\n\n## Building Stubs\n\n```go\ntype Foo interface {\n  Bar(x int) int\n}\n\nfunc SUT(f Foo) {\n \u002F\u002F ...\n}\n\n```\n\n```go\nfunc TestFoo(t *testing.T) {\n  ctrl := gomock.NewController(t)\n  defer ctrl.Finish()\n\n  m := NewMockFoo(ctrl)\n\n  \u002F\u002F Does not make any assertions. Executes the anonymous functions and returns\n  \u002F\u002F its result when Bar is invoked with 99.\n  m.\n    EXPECT().\n    Bar(gomock.Eq(99)).\n    DoAndReturn(func(_ int) int {\n      time.Sleep(1*time.Second)\n      return 101\n    }).\n    AnyTimes()\n\n  \u002F\u002F Does not make any assertions. Returns 103 when Bar is invoked with 101.\n  m.\n    EXPECT().\n    Bar(gomock.Eq(101)).\n    Return(103).\n    AnyTimes()\n\n  SUT(m)\n}\n```\n\n## Modifying Failure Messages\n\nWhen a matcher reports a failure, it prints the received (`Got`) vs the\nexpected (`Want`) value.\n\n```shell\nGot: [3]\nWant: is equal to 2\nExpected call at user_test.go:33 doesn't match the argument at index 1.\nGot: [0 1 1 2 3]\nWant: is equal to 1\n```\n\n### Modifying `Want`\n\nThe `Want` value comes from the matcher's `String()` method. If the matcher's\ndefault output doesn't meet your needs, then it can be modified as follows:\n\n```go\ngomock.WantFormatter(\n  gomock.StringerFunc(func() string { return \"is equal to fifteen\" }),\n  gomock.Eq(15),\n)\n```\n\nThis modifies the `gomock.Eq(15)` matcher's output for `Want:` from `is equal\nto 15` to `is equal to fifteen`.\n\n### Modifying `Got`\n\nThe `Got` value comes from the object's `String()` method if it is available.\nIn some cases the output of an object is difficult to read (e.g., `[]byte`) and\nit would be helpful for the test to print it differently. The following\nmodifies how the `Got` value is formatted:\n\n```go\ngomock.GotFormatterAdapter(\n  gomock.GotFormatterFunc(func(i interface{}) string {\n    \u002F\u002F Leading 0s\n    return fmt.Sprintf(\"%02d\", i)\n  }),\n  gomock.Eq(15),\n)\n```\n\nIf the received value is `3`, then it will be printed as `03`.\n\n[golang]:              http:\u002F\u002Fgolang.org\u002F\n[golang-install]:      http:\u002F\u002Fgolang.org\u002Fdoc\u002Finstall.html#releases\n[gomock-reference]:    https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgolang\u002Fmock\u002Fgomock\n[ci-badge]:            https:\u002F\u002Fgithub.com\u002Fgolang\u002Fmock\u002Factions\u002Fworkflows\u002Ftest.yaml\u002Fbadge.svg\n[ci-runs]:             https:\u002F\u002Fgithub.com\u002Fgolang\u002Fmock\u002Factions\n[reference-badge]:     https:\u002F\u002Fpkg.go.dev\u002Fbadge\u002Fgithub.com\u002Fgolang\u002Fmock.svg\n[reference]:           https:\u002F\u002Fpkg.go.dev\u002Fgithub.com\u002Fgolang\u002Fmock\n\n## Debugging Errors\n\n### reflect vendoring error\n\n```text\ncannot find package \".\"\n... github.com\u002Fgolang\u002Fmock\u002Fmockgen\u002Fmodel\n```\n\nIf you come across this error while using reflect mode and vendoring\ndependencies there are three workarounds you can choose from:\n\n1. Use source mode.\n2. Include an empty import `import _ \"github.com\u002Fgolang\u002Fmock\u002Fmockgen\u002Fmodel\"`.\n3. Add `--build_flags=--mod=mod` to your mockgen command.\n\nThis error is due to changes in default behavior of the `go` command in more\nrecent versions. More details can be found in\n[#494](https:\u002F\u002Fgithub.com\u002Fgolang\u002Fmock\u002Fissues\u002F494).\n","golang\u002Fmock 是一个为 Go 语言设计的模拟框架。它通过生成模拟接口帮助开发者进行单元测试，与 Go 自带的 `testing` 包无缝集成，同时也支持其他使用场景。该项目提供了一个名为 `mockgen` 的工具，能够基于源文件或反射模式自动生成模拟代码，支持指定导入、目标包名以及输出位置等参数配置，极大地简化了模拟对象的创建过程。适用于需要对依赖外部组件的 Go 应用程序进行隔离测试的场景。尽管官方已不再维护此项目，但其理念和技术实现仍被广泛认可和采用。",2,"2026-06-11 03:02:30","top_language"]