top

GoMock - a mock framework for Go.

Standard usage:

(1) Define an interface that you wish to mock.
      type MyInterface interface {
        SomeMethod(x int64, y string)
      }
(2) Use mockgen to generate a mock from the interface.
(3) Use the mock in a test:
      func TestMyThing(t *testing.T) {
        mockCtrl := gomock.NewController(t)
        defer mockCtrl.Finish()

        mockObj := something.NewMockMyInterface(mockCtrl)
        mockObj.EXPECT().SomeMethod(4, "blah")
        // pass mockObj to a real object and play with it.
      }

By default, expected calls are not enforced to run in any particular order. Call order dependency can be enforced by use of InOrder and/or Call.After. Call.After can create more varied call order dependencies, but InOrder is often more convenient.

The following examples create equivalent call order dependencies.

Example of using Call.After to chain expected call order:

firstCall := mockObj.EXPECT().SomeMethod(1, "first")
secondCall := mockObj.EXPECT().SomeMethod(2, "second").After(firstCall)
mockObj.EXPECT().SomeMethod(3, "third").After(secondCall)

Example of using InOrder to declare expected call order:

gomock.InOrder(
    mockObj.EXPECT().SomeMethod(1, "first"),
    mockObj.EXPECT().SomeMethod(2, "second"),
    mockObj.EXPECT().SomeMethod(3, "third"),
)

TODO:

- Handle different argument/return types (e.g. ..., chan, map, interface).

Imported by 140 package(s)

  1. bitbucket.org/plimble/gosnow/mock
  2. code.google.com/p/gomock/gomock/mock_matcher
  3. code.google.com/p/gomock/sample/mock_user
  4. github.com/3onyc/goirc/state
  5. github.com/3onyc/golog/logging
  6. github.com/Altoros/bosh-init/blobstore/mocks
  7. github.com/Altoros/bosh-init/cloud/mocks
  8. github.com/Altoros/bosh-init/cmd/mocks
  9. github.com/Altoros/bosh-init/config/mocks
  10. github.com/Altoros/bosh-init/deployment/agentclient/http/mocks
  11. github.com/Altoros/bosh-init/deployment/agentclient/mocks
  12. github.com/Altoros/bosh-init/deployment/disk/mocks
  13. github.com/Altoros/bosh-init/deployment/instance/mocks
  14. github.com/Altoros/bosh-init/deployment/instance/state/mocks
  15. github.com/Altoros/bosh-init/deployment/mocks
  16. github.com/Altoros/bosh-init/deployment/release/mocks
  17. github.com/Altoros/bosh-init/deployment/vm/mocks
  18. github.com/Altoros/bosh-init/installation/job/mocks
  19. github.com/Altoros/bosh-init/installation/mocks
  20. github.com/Altoros/bosh-init/installation/pkg/mocks
  21. github.com/Altoros/bosh-init/installation/tarball/mocks
  22. github.com/Altoros/bosh-init/registry/mocks
  23. github.com/Altoros/bosh-init/release/mocks
  24. github.com/Altoros/bosh-init/stemcell/mocks
  25. github.com/Altoros/bosh-init/templatescompiler/mocks
  26. github.com/Altoros/bosh-init/test_support/mocks
  27. github.com/Altoros/bosh-init/testutils/mocks
  28. github.com/Clever/cadvisor/utils/fs/mockfs
  29. github.com/CrowdStrike/gomock/sample/mock_user
  30. github.com/EPICPaaS/cadvisor/utils/fs/mockfs
  31. github.com/Gonk/goirc/state
  32. github.com/Ro0mquy/goirc/state
  33. github.com/StalkR/goirc/state
  34. github.com/TrollWarlord/goirc/state
  35. github.com/aaronwinter/goirc/state
  36. github.com/altoros/bosh-init/cpi/release/mocks
  37. github.com/altoros/bosh-init/state/job/mocks
  38. github.com/altoros/bosh-init/state/pkg/mocks
  39. github.com/arkadijs/cadvisor/utils/fs/mockfs
  40. github.com/bgmerrell/goirc/state
  41. github.com/bramp/goirc/state
  42. github.com/brysgo/gomock_ginkgo
  43. github.com/caglar10ur/cadvisor/utils/fs/mockfs
  44. github.com/calmh/goirc/state
  45. github.com/casualjim/go-curator/mock_zookeeper
  46. github.com/casualjim/go-curator/mocks
  47. github.com/cf-guardian/guardian-backend/utils/fileutils/mock_fileutils
  48. github.com/cf-guardian/guardian-backend/utils/syscall/mock_syscall
  49. github.com/cf-guardian/guardian/kernel/fileutils/mock_fileutils
  50. github.com/cf-guardian/guardian/kernel/syscall/mock_syscall
  51. github.com/chenyf/cadvisor/utils/fs/mockfs
  52. github.com/cnaize/cadvisor/utils/fs/mockfs
  53. github.com/codemac/pickett/io
  54. github.com/crankycoder/heka-mozsvc-plugins/testsupport
  55. github.com/darkliquid/goirc/state
  56. github.com/degupta/thrift/lib/go/test/tests
  57. github.com/denderello/cadvisor/utils/fs/mockfs
  58. github.com/discordianfish/cadvisor/utils/fs/mockfs
  59. github.com/djworth/goirc/state
  60. github.com/domluna/cadvisor/utils/fs/mockfs
  61. github.com/drnic/bosh-init/blobstore/mocks
  62. github.com/drnic/bosh-init/cloud/mocks
  63. github.com/drnic/bosh-init/deployment/agentclient/http/mocks
  64. github.com/drnic/bosh-init/deployment/agentclient/mocks
  65. github.com/drnic/bosh-init/deployment/disk/mocks
  66. github.com/drnic/bosh-init/deployment/instance/mocks
  67. github.com/drnic/bosh-init/deployment/mocks
  68. github.com/drnic/bosh-init/deployment/release/mocks
  69. github.com/drnic/bosh-init/deployment/stemcell/mocks
  70. github.com/drnic/bosh-init/deployment/vm/mocks
  71. github.com/drnic/bosh-init/installation/mocks
  72. github.com/drnic/bosh-init/registry/mocks
  73. github.com/drnic/bosh-init/release/mocks
  74. github.com/drnic/bosh-init/release/set/mocks
  75. github.com/drnic/bosh-init/templatescompiler/mocks
  76. github.com/endeveit/raven-go/raven
  77. github.com/feiyang21687/cadvisor/utils/fs/mockfs
  78. github.com/fluffle/goevent/event
  79. github.com/gamelost/goirc/state
  80. github.com/gonuts/goevent/event
  81. github.com/griffina/gpio/mock_gpio
  82. github.com/ha1t/goirc/state
  83. github.com/helmi03/golang-stuff/github.com/cloudfoundry/gorouter/test
  84. github.com/hmalphettes/cadvisor/utils/fs/mockfs
  85. github.com/huin/chunkymonkey/gamerules_mock
  86. github.com/hydrogen2005/heka/testsupport
  87. github.com/iansmith/pickett/io
  88. github.com/ilovewchao/withmock/scenarios/uses_gomock/dep1
  89. github.com/imosquera/uploadthis/util/mocks
  90. github.com/incredlabs/cadvisor/utils/fs/mockfs
  91. github.com/jbdalido/cadvisor/utils/fs/mockfs
  92. github.com/jbochi/heka/testsupport
  93. github.com/juliusv/cadvisor/utils/fs/mockfs
  94. github.com/justinsb/cadvisor/utils/fs/mockfs
  95. github.com/kevin1024/cadvisor/utils/fs/mockfs
  96. github.com/levb/heka-mozsvc-plugins/testsupport
  97. github.com/levigross/heka/testsupport
  98. github.com/liudch/cadvisor/utils/fs/mockfs
  99. github.com/lucy/goirc/state
  100. github.com/lukevers/goirc/state
  101. github.com/marcinwyszynski/weatherman
  102. github.com/marcosinger/withmock/scenarios/uses_gomock/dep1
  103. github.com/masagroup/goevent/event
  104. github.com/masagroup/goirc/state
  105. github.com/masagroup/golog/logging
  106. github.com/milliyang/golang-stuff/github.com/cloudfoundry/gorouter/test
  107. github.com/mindscratch/cadvisor/utils/fs/mockfs
  108. github.com/mitadmin/heka/testsupport
  109. github.com/mix3/goirc/state
  110. github.com/nemith/goirc/state
  111. github.com/nsjph/goirc/state
  112. github.com/ochinchina/thrift/lib/go/test/tests
  113. github.com/pchojnacki/heka/testsupport
  114. github.com/plimble/repass
  115. github.com/plimble/repass/mock_repass
  116. github.com/quadr/goirc/state
  117. github.com/quadr/golog/logging
  118. github.com/rafrombrc/gomock/sample/mock_user
  119. github.com/rafrombrc/heka/testsupport
  120. github.com/rjohnsondev/raven-go/raven
  121. github.com/rmorriso/goirc/state
  122. github.com/ro0mquy/goirc/state
  123. github.com/sadasant/goirc/state
  124. github.com/seven5/seven5/mock
  125. github.com/sevki/cadvisor/utils/fs/mockfs
  126. github.com/simon3z/cadvisor/utils/fs/mockfs
  127. github.com/sinopower/heka/testsupport
  128. github.com/sipin/gothrift/test/tests
  129. github.com/staven/goirc/state
  130. github.com/stone/goirc/state
  131. github.com/streamrail/cadvisor/utils/fs/mockfs
  132. github.com/taruti/goirc/state
  133. github.com/timkettering/goirc/state
  134. github.com/tlrx/heka/testsupport
  135. github.com/viniciusfeitosa/putin-terminal/mock
  136. github.com/vmarmol/cadvisor/utils/fs/mockfs
  137. github.com/voelzmo/bosh-init/state/job/mocks
  138. github.com/voelzmo/bosh-init/state/pkg/mocks
  139. github.com/wathiede/goirc/state
  140. github.com/yaotian/heka/testsupport

Imported only in test by 246 package(s)

  1. code.google.com/p/gomock/sample
  2. github.com/3onyc/goirc/client
  3. github.com/Altoros/bosh-init/cmd
  4. github.com/Altoros/bosh-init/deployment
  5. github.com/Altoros/bosh-init/deployment/instance
  6. github.com/Altoros/bosh-init/deployment/instance/state
  7. github.com/Altoros/bosh-init/deployment/release
  8. github.com/Altoros/bosh-init/installation
  9. github.com/Altoros/bosh-init/installation/pkg
  10. github.com/Altoros/bosh-init/templatescompiler
  11. github.com/CrowdStrike/gomock/sample
  12. github.com/EPICPaaS/cadvisor/utils/procfs
  13. github.com/Gonk/goirc/client
  14. github.com/Grigs-b/withmock/example
  15. github.com/KushalP/heka/pipeline
  16. github.com/KushalP/heka/plugins
  17. github.com/NixM0nk3y/heka/pipeline
  18. github.com/NixM0nk3y/heka/plugins
  19. github.com/QuenkTechnologies/pelau
  20. github.com/Ro0mquy/goirc/client
  21. github.com/StalkR/goirc/client
  22. github.com/TrollWarlord/goirc/client
  23. github.com/WiseBird/genetic_algorithm
  24. github.com/aaronwinter/goirc/client
  25. github.com/altoros/bosh-init/cmd
  26. github.com/altoros/bosh-init/cpi/release
  27. github.com/altoros/bosh-init/deployment
  28. github.com/altoros/bosh-init/installation
  29. github.com/altoros/bosh-init/state/job
  30. github.com/altoros/bosh-init/templatescompiler
  31. github.com/b1naryth1ef/chunkymonkey/src/chunkymonkey/command
  32. github.com/b1naryth1ef/chunkymonkey/src/chunkymonkey/physics
  33. github.com/barum/gomock/gomock
  34. github.com/barum/gomock/sample
  35. github.com/bgmerrell/goirc/client
  36. github.com/bramp/goirc/client
  37. github.com/brysgo/gofigure/decision_tree
  38. github.com/brysgo/gofigure/prediction_forest
  39. github.com/c4e8ece0/gofigure/decision_tree
  40. github.com/c4e8ece0/gofigure/prediction_forest
  41. github.com/calmh/goirc/client
  42. github.com/carlosdp/heka/pipeline
  43. github.com/carlosdp/heka/plugins
  44. github.com/casualjim/go-curator
  45. github.com/cf-guardian/guardian-backend/rootfs
  46. github.com/cf-guardian/guardian/kernel/rootfs
  47. github.com/cfsalguero/test_mongo_mock/controllers
  48. github.com/cloudfoundry-attic/gonatsd/gonatsd
  49. github.com/codemac/pickett/core
  50. github.com/crankycoder/heka-mozsvc-plugins
  51. github.com/daimatz/gomock_example/twitter_bot
  52. github.com/darkliquid/goirc/client
  53. github.com/denderello/cadvisor/utils/procfs
  54. github.com/didip/heka/pipeline
  55. github.com/didip/heka/plugins
  56. github.com/djworth/goirc/client
  57. github.com/drnic/bosh-init/cmd
  58. github.com/drnic/bosh-init/deployment
  59. github.com/drnic/bosh-init/deployment/instance
  60. github.com/drnic/bosh-init/deployment/release
  61. github.com/drnic/bosh-init/installation
  62. github.com/drnic/bosh-init/templatescompiler
  63. github.com/gamelost/goirc/client
  64. github.com/ha1t/goirc/client
  65. github.com/helmi03/golang-stuff/github.com/cloudfoundry/gorouter
  66. github.com/hmalphettes/cadvisor/utils/procfs
  67. github.com/huin/artemis/net/artproto
  68. github.com/huin/chunkymonkey/command
  69. github.com/huin/chunkymonkey/gamerules
  70. github.com/huin/chunkymonkey/physics
  71. github.com/hydrogen2005/heka/pipeline
  72. github.com/iansmith/pickett/core
  73. github.com/ilovewchao/withmock-test
  74. github.com/ilovewchao/withmock-test/directory-issue
  75. github.com/ilovewchao/withmock/example
  76. github.com/ilovewchao/withmock/scenarios/basic
  77. github.com/ilovewchao/withmock/scenarios/basic_stdlib
  78. github.com/ilovewchao/withmock/scenarios/build_constraints
  79. github.com/ilovewchao/withmock/scenarios/embedding
  80. github.com/ilovewchao/withmock/scenarios/encoding
  81. github.com/ilovewchao/withmock/scenarios/func_literals
  82. github.com/ilovewchao/withmock/scenarios/has_init
  83. github.com/ilovewchao/withmock/scenarios/interface
  84. github.com/ilovewchao/withmock/scenarios/interface_pkg
  85. github.com/ilovewchao/withmock/scenarios/issue10
  86. github.com/ilovewchao/withmock/scenarios/issue11
  87. github.com/ilovewchao/withmock/scenarios/issue16
  88. github.com/ilovewchao/withmock/scenarios/issue17
  89. github.com/ilovewchao/withmock/scenarios/issue18
  90. github.com/ilovewchao/withmock/scenarios/issue19
  91. github.com/ilovewchao/withmock/scenarios/issue23/pkg1
  92. github.com/ilovewchao/withmock/scenarios/issue23/pkg2
  93. github.com/ilovewchao/withmock/scenarios/issue24
  94. github.com/ilovewchao/withmock/scenarios/issue25
  95. github.com/ilovewchao/withmock/scenarios/issue27
  96. github.com/ilovewchao/withmock/scenarios/issue28
  97. github.com/ilovewchao/withmock/scenarios/issue32
  98. github.com/ilovewchao/withmock/scenarios/issue33
  99. github.com/ilovewchao/withmock/scenarios/issue34
  100. github.com/ilovewchao/withmock/scenarios/issue35
  101. github.com/ilovewchao/withmock/scenarios/issue8
  102. github.com/ilovewchao/withmock/scenarios/issue9
  103. github.com/ilovewchao/withmock/scenarios/missing
  104. github.com/ilovewchao/withmock/scenarios/multiple_pkgs/one
  105. github.com/ilovewchao/withmock/scenarios/multiple_pkgs/three
  106. github.com/ilovewchao/withmock/scenarios/multiple_pkgs/two
  107. github.com/ilovewchao/withmock/scenarios/new_methods
  108. github.com/ilovewchao/withmock/scenarios/nongocode
  109. github.com/ilovewchao/withmock/scenarios/other_c_code
  110. github.com/ilovewchao/withmock/scenarios/protobuf
  111. github.com/ilovewchao/withmock/scenarios/replace
  112. github.com/ilovewchao/withmock/scenarios/runtime
  113. github.com/ilovewchao/withmock/scenarios/shared_types
  114. github.com/ilovewchao/withmock/scenarios/stdlib_cross
  115. github.com/ilovewchao/withmock/scenarios/uses_gomock
  116. github.com/ilovewchao/withmock/scenarios/var_slice
  117. github.com/ilovewchao/withmock/scenarios/with_deps
  118. github.com/imosquera/uploadthis/conf
  119. github.com/imosquera/uploadthis/execution
  120. github.com/imosquera/uploadthis/hooks
  121. github.com/imosquera/uploadthis/upload
  122. github.com/imosquera/uploadthis/uploadthis
  123. github.com/imosquera/withmock-examples/baz
  124. github.com/imosquera/withmock-examples/foo
  125. github.com/imosquera/withmock/example
  126. github.com/incredlabs/cadvisor/utils/procfs
  127. github.com/iyee/gomock/gomock
  128. github.com/iyee/gomock/sample
  129. github.com/jbdalido/cadvisor/utils/procfs
  130. github.com/jbli/heka/pipeline
  131. github.com/jbli/heka/plugins
  132. github.com/jbochi/heka/pipeline
  133. github.com/jeady/lmk/engine
  134. github.com/jesand/webcp/crawl
  135. github.com/jhawk28/heka/pipeline
  136. github.com/jhawk28/heka/plugins
  137. github.com/joesustaric/gomock/sample
  138. github.com/josedonizetti/heka/pipeline
  139. github.com/josedonizetti/heka/plugins
  140. github.com/jvehent/heka/pipeline
  141. github.com/jvehent/heka/plugins
  142. github.com/kevin1024/cadvisor/utils/procfs
  143. github.com/kushalp/heka/pipeline
  144. github.com/kushalp/heka/plugins
  145. github.com/lann/heka/pipeline
  146. github.com/lann/heka/plugins
  147. github.com/levb/heka-mozsvc-plugins
  148. github.com/levb/heka/pipeline
  149. github.com/levb/heka/plugins
  150. github.com/levigross/heka/pipeline
  151. github.com/liudch/cadvisor/utils/procfs
  152. github.com/lucy/goirc/client
  153. github.com/lukevers/goirc/client
  154. github.com/lunastorm/withmock/example
  155. github.com/marcosinger/withmock/example
  156. github.com/marcosinger/withmock/scenarios/basic
  157. github.com/marcosinger/withmock/scenarios/basic_stdlib
  158. github.com/marcosinger/withmock/scenarios/build_constraints
  159. github.com/marcosinger/withmock/scenarios/embedding
  160. github.com/marcosinger/withmock/scenarios/func_literals
  161. github.com/marcosinger/withmock/scenarios/has_init
  162. github.com/marcosinger/withmock/scenarios/interface
  163. github.com/marcosinger/withmock/scenarios/interface_pkg
  164. github.com/marcosinger/withmock/scenarios/issue10
  165. github.com/marcosinger/withmock/scenarios/issue11
  166. github.com/marcosinger/withmock/scenarios/issue16
  167. github.com/marcosinger/withmock/scenarios/issue17
  168. github.com/marcosinger/withmock/scenarios/issue18
  169. github.com/marcosinger/withmock/scenarios/issue19
  170. github.com/marcosinger/withmock/scenarios/issue23/pkg1
  171. github.com/marcosinger/withmock/scenarios/issue23/pkg2
  172. github.com/marcosinger/withmock/scenarios/issue24
  173. github.com/marcosinger/withmock/scenarios/issue25
  174. github.com/marcosinger/withmock/scenarios/issue27
  175. github.com/marcosinger/withmock/scenarios/issue8
  176. github.com/marcosinger/withmock/scenarios/issue9
  177. github.com/marcosinger/withmock/scenarios/missing
  178. github.com/marcosinger/withmock/scenarios/multiple_pkgs/one
  179. github.com/marcosinger/withmock/scenarios/multiple_pkgs/three
  180. github.com/marcosinger/withmock/scenarios/multiple_pkgs/two
  181. github.com/marcosinger/withmock/scenarios/new_methods
  182. github.com/marcosinger/withmock/scenarios/nongocode
  183. github.com/marcosinger/withmock/scenarios/runtime
  184. github.com/marcosinger/withmock/scenarios/shared_types
  185. github.com/marcosinger/withmock/scenarios/uses_gomock
  186. github.com/marcosinger/withmock/scenarios/with_deps
  187. github.com/marmelab/gaudi/container
  188. github.com/marmelab/gaudi/gaudi
  189. github.com/masagroup/goirc/client
  190. github.com/masagroup/gomock/gomock
  191. github.com/masagroup/gomock/sample
  192. github.com/mbinge/gomock/gomock
  193. github.com/mbinge/gomock/sample
  194. github.com/megamsys/heka/pipeline
  195. github.com/megamsys/heka/plugins
  196. github.com/milliyang/golang-stuff/github.com/cloudfoundry/gorouter
  197. github.com/mindscratch/cadvisor/utils/procfs
  198. github.com/mitadmin/heka/pipeline
  199. github.com/mix3/goirc/client
  200. github.com/nemith/goirc/client
  201. github.com/nsjph/goirc/client
  202. github.com/oldmantaiter/heka/pipeline
  203. github.com/oldmantaiter/heka/plugins
  204. github.com/onnoll/advanced-gomocking-test/client
  205. github.com/pchojnacki/heka/pipeline
  206. github.com/quadr/goirc/client
  207. github.com/quenktech/pelau
  208. github.com/quenktechnologies/pelau
  209. github.com/qur/gomock/gomock
  210. github.com/qur/gomock/sample
  211. github.com/rafrombrc/gomock/sample
  212. github.com/rafrombrc/heka/pipeline
  213. github.com/rakutentech/bosh-init/cmd
  214. github.com/rakutentech/bosh-init/deployment
  215. github.com/rakutentech/bosh-init/installation
  216. github.com/rakutentech/bosh-init/templatescompiler
  217. github.com/rmorriso/goirc/client
  218. github.com/ro0mquy/goirc/client
  219. github.com/sadasant/goirc/client
  220. github.com/shutej/gomock/gomock
  221. github.com/shutej/gomock/sample
  222. github.com/sinopower/heka/pipeline
  223. github.com/staven/goirc/client
  224. github.com/stone/goirc/client
  225. github.com/streamrail/cadvisor/utils/procfs
  226. github.com/taruti/goirc/client
  227. github.com/tgulacsi/heka-plugins/http
  228. github.com/timkettering/goirc/client
  229. github.com/tlrx/heka/pipeline
  230. github.com/udoyu/gomock/gomock
  231. github.com/udoyu/gomock/sample
  232. github.com/victorpoluceno/heka/pipeline
  233. github.com/victorpoluceno/heka/plugins
  234. github.com/viniciusfeitosa/putin-terminal
  235. github.com/voelzmo/bosh-init/cmd
  236. github.com/voelzmo/bosh-init/deployment
  237. github.com/voelzmo/bosh-init/installation
  238. github.com/voelzmo/bosh-init/state/job
  239. github.com/voelzmo/bosh-init/templatescompiler
  240. github.com/wathiede/goirc/client
  241. github.com/wmadisonDev/heka/pipeline
  242. github.com/wmadisonDev/heka/plugins
  243. github.com/worr/secstring
  244. github.com/yaotian/heka/pipeline
  245. github.com/yubo/gonatsd/gonatsd
  246. gitlab.com/worr/secstring.git

Test imports 1 package(s)

  1. code.google.com/p/gomock/gomock/mock_matcher