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


  • 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.



GopherCon 2017: Mitchell Hashimoto - Advanced Testing with Go by Mitchell Hashimoto