Standard library / testing

testing.B.Fatal()

Mark failure and terminate the current test or benchmark goroutine via runtime.Goexit. Deferred calls and registered cleanup run; do not call from a worker goroutine. This intentionally failing fixture should exit 1. Expected process exit: 1; output contains ['FAIL', 'cleanup reached', 'diagnostic']. Run as a _test.go file using the Go test harness.

Formal Syntax & Structure

go syntaxgo
func (c *B) Fatal(args ...any)

Parameters & Attributes

NameTypeDescription
args...anyValues to format or log.

Working Example

Example Snippetgo
package main
import (  "fmt"  "testing")
func BenchmarkReference(b *testing.B) {  b.Cleanup(func() { fmt.Println("cleanup reached") })  b.Fatal("diagnostic")  fmt.Println("continued", b.Failed())}
Go Reference