func TestAddition(t *testing.T) { a := 2 b := 3 expected := 5 actual := a + b if actual != expected { t.Errorf("Addition test failed: expected %d, got %d", expected, actual) } }
func TestDivision(t *testing.T) { a := 10 b := 0 _, err := division(a, b) if err == nil { t.Errorf("Division test failed: expected an error, got nil") } } func division(a, b int) (int, error) { if b == 0 { return 0, fmt.Errorf("division by zero") } return a / b, nil }This is another unit test that tests division by zero. It uses the testing.T type to report an error if the division function doesn't return an error when dividing by zero. In both examples, the testing.T type is used to report errors if the tests fail, and to control the status of the tests with methods like t.Errorf() and t.Run(). Overall, the "testing" package is a standard library package in Go language that provides a framework for writing and running unit tests for Go programs.