Notes on talk - Advanced testing in golang by Mitchell Hashimoto
This talk has really great takeaways which are worth considering while writing your tests
Test Fixtures
- “go test” sets pwd as package directory
Test Helpers
- should never return an error they should access to the
*testing.T
object - call
t.Helper()
in the beginning (works only for go1.9+) - for things reqiuiring clean up return closures
Configurability
- Unconfigurable behavior is often a point of difficulty for tests. e.g. ports, timeouts, paths.
- Over-parameterize structs to allow tests to fine-tune their behavior
- It’s ok to make these configs unexported so only tests can set them.