Last Updated: May 22, 2026
Tests that depend on file input or produce file output need a place to keep their data. Go has a strong convention for this: a testdata/ directory next to the test file, plus a handful of standard library helpers for temporary directories, environment variables, and golden-file comparisons. This chapter covers the testdata/ convention, reading fixtures with os.ReadFile, the golden file pattern with an -update flag, and the t.TempDir() and t.Setenv() helpers for tests that need a clean scratch space.