package main import ( "testing" ) func TestExample(t *testing.T){ if 1+1 != 2 { t.B.Fatal("1+1 did not equal 2.") } }
package main import ( "testing" ) func TestDivision(t *testing.T){ numerator := 10 denominator := 0 if denominator == 0 { t.B.Fatal("division by zero") } result := numerator/denominator if result != 5 { t.B.Fatal("division was incorrect") } }This example tests division and checks for division by zero. If division by zero occurs, we immediately abort the test and log a fatal error message. Overall, B.Fatal is an important function to use when a test must be aborted immediately due to a serious error. It is included in the testing package in Go.