Standard library / testing

testing.T.Run()

Execute a named subtest and return whether it succeeded. A subtest calling Parallel may continue after Run returns. Expected stdout: 'TestReference/child\ntrue\nPASS\n'. Run as a _test.go file using the Go test harness.

Formal Syntax & Structure

go syntaxgo
func (t *T) Run(name string, f func(t *T)) bool

Parameters & Attributes

NameTypeDescription
namestringName of the nested test or benchmark.
ffunc(t *T)Function under test or callback to run.

Return Value

bool

Result of the operation described above.

Working Example

Example Snippetgo
package main
import (  "fmt"  "testing")
func TestReference(t *testing.T) {  ok := t.Run("child", func(t *testing.T) { fmt.Println(t.Name()) })  fmt.Println(ok)}
Go Reference