Go has built-in testing. Write test functions in files ending with _test.go:
// add_test.go
func TestAdd(t *testing.T) {
result := Add(2, 3)
if result != 5 {
t.Errorf("Add(2, 3) = %d; want 5", result)
}
}
Run tests with go test. Test functions must start with Test and take a *testing.T parameter. Writing tests ensures your functions work correctly and continue working as you change code.