- A stub satisfies a particular interface and returns canned answers for every invocation to the methods it implements. Mocks allow us to specify the following in a declarative way:
- The order and parameters of the expected set of method invocations
- The set of values to be returned for each combination of inputs
- A fake object provides a fully working implementation whose behavior matches the objects that they are meant to substitute. For example, instead of having our tests communicate with a real key-value (KV) store, we might inject a fake object that provides a compatible, in-memory implementation of the KV store's API.
- A table-driven test consists of three main components:
- A type that encapsulates the parameters for running the test and its expected outcome. In Go programs, this is typically facilitated using an anonymous struct.
- A slice of test cases to...