Standard library / testing
testing.M.Run()
Execute the test suite and return its process exit code. TestMain may perform setup and teardown around this call. Expected process exit: 0; output contains ['setup', 'test body', 'PASS', 'teardown 0']. Run as a _test.go file using the Go test harness.
Formal Syntax & Structure
go syntaxgo
func (m *M) Run() (code int)Return Value
(code int)
Result of the operation described above.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "testing")
func TestMain(m *testing.M) { fmt.Println("setup") code := m.Run() fmt.Println("teardown", code) os.Exit(code)}func TestReference(t *testing.T) { fmt.Println("test body") }