This chapter will be different from the previous chapters; this will focus on testing and testing methodologies. Go provides excellent testing support out of the box, however, it can be difficult to understand coming from more dynamic languages where monkey patching and mocking are relatively straightforward.
Go testing encourages a specific structure for your code, in particular, testing and mocking interfaces is very straightforward and well supported. Some types of code can be more difficult to test. For example, it can be difficult to test code that makes use of package-level global variables, places that have not been abstracted into interfaces, and structs that have non-exported variables or methods. This chapter will share some recipes for testing Go code.