Testing in Go

In Go, testing is usually done by creating files that end with _test.go. These files are compiled together with the main code and can call functions from the package being tested.
A test function must start with the word Test, and it receives a pointer to testing.T. If the test fails, Go reports the function name and the failing assertion.
When you run go test -v in a package folder, Go automatically finds all _test.go files, compiles them, and runs the test functions.

Simple example

package mymath

func Add(a, b int) int {
    return a + b
}

$ cat mathutils_test.go

package mymath
import "testing"

func TestAdd(t *testing.T) {
    got := Add(2, 3)
    want := 5

    if got != want {
        t.Fatalf("Add(2, 3) = %d; want %d", got, want)
    }
}