Standard library / testing

testing.F.Helper()

Mark the calling function as a helper so diagnostic locations point past it. This intentionally failing example demonstrates helper diagnostics. Expected process exit: 1; output contains ['FAIL', 'helper diagnostic', 'after helper']. Run as a _test.go file using the Go test harness.

Formal Syntax & Structure

go syntaxgo
func (f *F) Helper()

Working Example

Example Snippetgo
package main
import (  "fmt"  "testing")
func check(f *testing.F) { f.Helper(); f.Error("helper diagnostic") }func FuzzReference(f *testing.F) {  check(f)  fmt.Println("after helper")  f.Add("demo")  f.Fuzz(func(t *testing.T, s string) {    if s != "demo" {      t.Fatal(s)    }  })}
Go Reference