Standard library / testing

testing.F.Fuzz()

Register a fuzz target with *testing.T and supported input types; go test without -fuzz runs the seed corpus. Expected stdout: 'seed checked\nPASS\n'. Run as a _test.go file using the Go test harness.

Formal Syntax & Structure

go syntaxgo
func (f *F) Fuzz(ff any)

Parameters & Attributes

NameTypeDescription
ffanyFuzz target function with a *testing.T first parameter and supported input types.

Working Example

Example Snippetgo
package main
import (  "fmt"  "strings"  "testing")
func FuzzReference(f *testing.F) {  f.Add("abc")  f.Fuzz(func(t *testing.T, s string) {    if strings.ToUpper(strings.ToUpper(s)) != strings.ToUpper(s) {      t.Fatal("not idempotent")    }    fmt.Println("seed checked")  })}
Go Reference