The unit under test
In Chapter 1, Getting to Grips with Test-Driven Development, we discussed the structure of tests using the Arrange-Act-Assert (AAA) pattern. We also briefly mentioned that the Arrange step sets up the Unit Under Test (UUT) and its dependencies. The test then exercises and verifies the functionality of the UUT.
In Go, source code is organized into packages and modules. We will begin by exploring what these are and how they work and then look at how test files fit into this structure. A solid understanding of the power of packages will set the scene for us to begin considering not only how to write tests, but what to test.
Modules and packages
If you have worked with Go for a while, you might be familiar with Go’s module system, which was introduced as the default dependency management solution in Go 1.13. The latest Go version at the time of writing is version 1.19, so the module system has been the standard solution for some time.
Modules
A...