func TestMyFunction(t *testing.T) { result := myFunction(4) if result != 7 { t.Fatalf("Expected 7 but got %d", result) } }
func TestMyOtherFunction(t *testing.T) { result, err := myOtherFunction(10) if err != nil { t.Fatalf("Unexpected error: %s", err) } if result != "success" { t.Fatalf("Expected 'success' but got '%s'", result) } }This example shows a test function that calls `myOtherFunction` with an input of 10 and expects a result of "success". If there is an error returned by the function, we log an error message and stop the test. If the result is not "success", we log another error message and stop the test. In both examples, we use `testing.T.Fatalf` to log error messages and stop the current test if necessary. This function is part of the testing package library in Go.