Go has a built-in support for unit testing. Writing tests is easy: just create some
*_test.go files with
func Test*(testing *T) functions. While providing a wide set of methods, the standard library does not have any mocks to use in tests. For example, there’s no common way to substitute
os package behaviour without using third-party libraries or running the tests in a Docker container.
Fortunately, there are some open-source libraries that provide mock objects. Here’s a list of them:
- Environment variables:
Feel free to mention me on Twitter if you know any other good libraries!