How it works...
The generated mock objects allow tests to specify what arguments are expected, the number of times a function will be called, and what to return, and they allow us to set additional artifacts, for example, we could write to a channel directly if the original function had a similar workflow. The interface_test.go file showcases some examples of using mock objects while calling them in-line. Generally, tests will look more like exec_test.go where we'll want intercept interface function calls performed by our actual code and change their behavior at test time.
The exec_test.go file also showcases how you might use mocked objects in a table-driven test environment. The Any() function means that the mocked function can be called ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access