This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

Radar · Go · Archive · Week 15 · Apr 7 – 13, 2025

testing: store test artifacts

Worth knowingstdlib

What changed
The testing.TB interface will get an ArtifactDir() string method, and go test will gain a -artifacts flag that causes the directory to be created under the test output directory.
Production impact
The source does not say.
Try it
Run go test -artifacts on a package that writes files to the directory returned by t.ArtifactDir().
Source
github.com/golang/go/issues/71287

Understand it, then run it

The Go testing framework lets you write tests that can create temporary files. Until now, those files were deleted when the test finished, so you couldn’t keep them around to look at later. A new method, ArtifactDir, will be added to the testing.TB interface. When you run go test with the -artifacts flag, the method will give you a directory that lives under the test output folder and stays after the test ends. If you run tests without the flag, ArtifactDir still returns a temporary directory that is removed when the test completes, so existing tests keep working.

Run it now

Todaygo
// This program demonstrates how test artifacts are stored today.
// Since the proposed ArtifactDir method is not yet available in Go 1.27.1,
// tests use a temporary directory created with os.MkdirTemp, which is
// automatically removed when the test finishes.  The program simply
// creates such a directory, prints its path, and deletes it.
package main

import (
	"fmt"
	"os"
)

func main() {
	// Create a temporary directory for test artifacts.
	dir, err := os.MkdirTemp("", "test-artifacts-")
	if err != nil {
		fmt.Println("error creating temp dir:", err)
		return
	}
	// Ensure the directory is removed after use.
	defer os.RemoveAll(dir)

	// Print the directory path so a user can inspect it.
	fmt.Println("Test artifact directory:", dir)
}

What it printed when we ran it on Go 1.27.1

Test artifact directory: /work/tmp/test-artifacts-2195789528

Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed