Github.com/uber/mock: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 9: Line 9:


=<tt>mockgen</tt>=
=<tt>mockgen</tt>=
To generate the mock code at stdout:
<syntaxhighlight lang='bash'>
mockgen <package_import_path> <InterfaceName>[,<InterfaceName>]
</syntaxhighlight>


=Programming Model=
=Programming Model=

Revision as of 18:51, 16 July 2024

External

Internal

Overview

Installation

mockgen

To generate the mock code at stdout:

mockgen <package_import_path> <InterfaceName>[,<InterfaceName>]

Programming Model

Setup Expectations

Define the Behavior of a Method

Configuring a mock to handle a specific method call.

someMock.EXPECT().SomeMethod(gomock.Any(), "some specific value").Return("some other value")

Note that if the method is not called at the end of the test, the mock will fail the test with:

missing call(s) to *mock_pkg.MockSomething.SomeMethod(...)
aborting test due to missing call(s)