This chapter will be different from the previous chapters; this chapter will focus on testing and testing methodologies. Go provides excellent testing support out of the box. However, it can be difficult to understand for developers 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 structures that have non-exported variables or methods. This chapter will share some recipes for testing Go code.
In this chapter, we will cover the following recipes:
- Mocking using the standard library ...