Menu

1 / 3

Go's t.ArtifactDir: Keep the Files a Failing Test Wrote With go test -artifacts

DEV Community: go·Gabriel Anhaia·8 days ago
#hHFepla4
#devtogo#devto#dev#test#directory
Reading 0:00
15s threshold

Book: The Complete Guide to Go Programming

Also by me: Pocket Guides for Developers — the 8-book series

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

The CI job is red. The log says report differs from golden . The test wrote the rendered report and a diff to disk before it failed, and you would give a lot to open those two files. You can't. They lived in t.TempDir() , and the testing docs are clear about what happens next: "The directory is automatically removed when the test and all its subtests complete." The runner is gone too.

So you rerun locally, fail to reproduce it, add a t.Log that dumps 200 lines of report into the job output, and push again.

Go 1.26 , released in February 2026, ships a standard answer. T.ArtifactDir , B.ArtifactDir and F.ArtifactDir "return a directory in which to write test output files (artifacts)." Pass -artifacts to go test and that directory survives under -outputdir .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.