Testing in Go is built right into the standard library with the package testing. It’s simple, convention-driven, and designed to run with the Go toolchain. Here’s how it works:
Test files must end with _test.go.
Example: math_test.go.
Test.testing.T.package math
import "testing"
func TestAdd(t *testing.T) {
got := Add(2, 3)
want := 5
if got != want {
t.Errorf("Add(2,3) = %d; want %d", got, want)
}
}
Run inside your project/module with:
go test ./...
or in a single package:
go test
With verbose output:
go test -v