func TestSomething(t *testing.T) { if 1+1 != 2 { t.FailNow() } // rest of the test code }
func TestSomething(t *testing.T) { setup(t) defer cleanup(t) // rest of the test code } func setup(t *testing.T) { // set up code if err != nil { t.FailNow() } } func cleanup(t *testing.T) { // cleanup code }This example shows how the `FailNow()` method can be used inside a setup function to immediately stop the test if there is an error in the setup process. Package/Library: This method is from the standard testing package in Go.