{"id":32420758,"url":"https://github.com/mynihongo/mockgen","last_synced_at":"2025-10-25T17:58:21.730Z","repository":{"id":46024604,"uuid":"410533225","full_name":"MyNihongo/mockgen","owner":"MyNihongo","description":"A mock code autogenerator for Go","archived":false,"fork":false,"pushed_at":"2021-11-19T12:02:21.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-06-21T18:48:29.812Z","etag":null,"topics":["generation","generator","go","golang","mock","mockgen","mocking","mocks","stretchr","testify","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MyNihongo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-26T11:29:10.000Z","updated_at":"2021-11-19T12:01:59.000Z","dependencies_parsed_at":"2022-09-14T11:13:20.819Z","dependency_job_id":null,"html_url":"https://github.com/MyNihongo/mockgen","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/MyNihongo/mockgen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MyNihongo%2Fmockgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MyNihongo%2Fmockgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MyNihongo%2Fmockgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MyNihongo%2Fmockgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MyNihongo","download_url":"https://codeload.github.com/MyNihongo/mockgen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MyNihongo%2Fmockgen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":280995962,"owners_count":26426667,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-25T02:00:06.499Z","response_time":81,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generation","generator","go","golang","mock","mockgen","mocking","mocks","stretchr","testify","testing"],"created_at":"2025-10-25T17:57:58.854Z","updated_at":"2025-10-25T17:58:21.722Z","avatar_url":"https://github.com/MyNihongo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Mockgen: Mock generation in Go\nMockgen is an utility for [testify](https://github.com/stretchr/testify) which generates the mundane mock initialisation code such as:\n\n- mock classes of all services of a struct;\n- type-safe setup methods (`On(\"FunctionName\")` and `Return()`);\n- `AssertExpectations` for all services of a struct.\n\n### Installing\nInstall the CLI for code generation\n```go\ngo get github.com/MyNihongo/mockgen/cmd/mockgen\n```\n### Add `go generate` for required mocks\n```go\n//go:generate mockgen impl1:Impl1Service\npackage mocking\n\nimport (\n\t\"github.com/MyNihongo/mockgen/mocking/pkg1\"\n\t\"github.com/MyNihongo/mockgen/mocking/pkg2\"\n)\n\ntype impl1 struct {\n\tser1 pkg1.Service1_1\n\tser2 pkg2.Service2_1\n}\n\ntype Impl1Service interface {\n\tFoo()\n}\n\nfunc (i *impl1) Foo() {\n\ti.ser1.Foo(\"string\", 12)\n\ti.ser2.Foo(\"string1\", \"string2\")\n}\n```\nThis will generate quite a lot of code, so please go to [mock_gen_test.go](examples/mock_gen_test.go) to see what is actually generated.\n\n#### Command samples\nUnlimited number of services can be passed for generation.  \nA single entry may be `structType` or `structType:interfaceType`.\n```sh\nmockgen service1:Service1 service2:Service2 service3:Service3\n```\nGenerate mocks for *service1*, *service2* and *service3* with interfaces.\n```sh\nmockgen service1:Service1 service2\n```\nGenerate a mock for *service1* with its interface; Generate a mock for *service2* without an interface.\n\n## Keep the package reference\nCommand `go mod tidy` will remove the reference of Mockgen by default. In order to keep the reference create a dummy file somewhere and import a dummy type.\n```go\npackage pkg\n\nimport \"github.com/MyNihongo/mockgen\"\n\nvar _ mockgen.Reference\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmynihongo%2Fmockgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmynihongo%2Fmockgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmynihongo%2Fmockgen/lists"}