Go Tutorial #17: Testing in Go
In the previous tutorial, you built REST APIs with Gin. Now it is time to test your code. Go has a powerful testing framework built into the standard library — no external dependencies needed. Testing in Go is simple by design. Test files live next to the code they test, and you run them with one command: go test. Your First Test Create a file called math.go: package math func Add(a, b int) int { return a + b } func Divide(a, b int) (int, error) { if b == 0 { return 0, fmt.Errorf("cannot divide by zero") } return a / b, nil } Now create math_test.go in the same directory: ...