Testing Go Code

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 ...

Get Go Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.