Mocking and Assertion Frameworks
In the previous chapter, we explored the fundamentals of writing tests in Go. We explored the importance of packages, the organization of test files alongside source code, and how to use Go’s testing
package to write tests and benchmarks.
We demonstrated the concepts and fundamentals of writing tests in Go with code samples from the Calculator
use case. The simple examples we have looked at so far have not included any external dependencies, which can make test setup and verification much more complex.
In this chapter, we will begin to look at how we can isolate the unit under test from its dependencies, keeping testing and assertions as simple and fast as possible. The easiest way to achieve this in Go is by leveraging the power of interfaces.
We will expand upon the Calculator
example by introducing dependencies to our main components. Then, we will learn how to generate mocks for these dependencies of the unit under test (UUT), enabling...