Photo by Fabian Grohs on Unsplash

Go provides you all the tools you need to achieve mocking and avoid certain behaviors in your tests. First class functions and interfaces with implicit satisfaction are very powerful language elements. Third party mocking tools may be useful add-ons, but it is my opinion that you should see what you can do with the tools in the language before seeking them out.

In this post, I will demonstrate different mocking techniques and describe the situations that may lead you to them.

5 Mocking Techniques:

  1. Higher-Order Functions
  2. Monkey Patching
  3. Interface Substitution
  4. Embedding Interfaces
  5. Mocking out Downstream HTTP Calls with net/http/httptest



Full-Stack Engineer at CB Insights

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store