Standard library / testing
testing.B.Error()
Mark the current test or benchmark as failed without stopping execution. Logs a diagnostic. This intentionally failing fixture should exit 1. Expected process exit: 1; output contains ['FAIL', 'cleanup reached', 'diagnostic', 'continued true']. Run as a _test.go file using the Go test harness.
Formal Syntax & Structure
go syntaxgo
func (c *B) Error(args ...any)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| args | ...any | Values 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.Error("diagnostic") fmt.Println("continued", b.Failed())}