Standard library / testing

testing.F.TempDir()

Create a temporary directory owned by the testing scope and remove it after cleanup. Do not rely on the generated name. Expected process exit: 0; output contains ['PASS', 'directory true']. Run as a _test.go file using the Go test harness.

Formal Syntax & Structure

go syntaxgo
func (c *F) TempDir() string

Return Value

string

Result of the operation described above.

Working Example

Example Snippetgo
package main
import (  "fmt"  "os"  "testing")
func FuzzReference(f *testing.F) {  d := f.TempDir()  info, err := os.Stat(d)  fmt.Println("directory", err == nil && info.IsDir())  f.Add("demo")  f.Fuzz(func(t *testing.T, s string) {    if s != "demo" {      t.Fatal(s)    }  })}
Go Reference