Github.com/uber/mock: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=External= * https://pkg.go.dev/go.uber.org/mock/gomock =Internal= =Overview=")
 
 
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:
* https://pkg.go.dev/go.uber.org/mock/gomock
* https://pkg.go.dev/go.uber.org/mock/gomock
=Internal=
=Internal=
* [[Go_Testing#Mocks|Go Testing]]
=Overview=
=Overview=
=Programming Model=
==Setup Expectations==
===Define the Behavior of a Method===
Configuring a mock to handle a specific method call.
<syntaxhighlight lang='go'>
someMock.EXPECT().SomeMethod(gomock.Any(), "some specific value").Return("some other value")
</syntaxhighlight>
Note that if the method is not called at the end of the test, the mock will fail the test with:
<font size=-2>
missing call(s) to *mock_pkg.MockSomething.SomeMethod(...)
aborting test due to missing call(s)
</font>

Latest revision as of 16:51, 26 April 2024

External

Internal

Overview

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)