test function

A Go function whose name starts with Test and which takes a *testing.T, so go test finds and runs it automatically.

In more detail

Name it after the behaviour it checks, such as TestHealthy or TestParsePortError, so a failure tells you what broke. Inside, compare what you got with what you wanted and report a mismatch through t.

Example

func TestHealthy(t *testing.T) {
	if !healthy(204) {
		t.Error("success code should be healthy")
	}
}

Related terms

Taught in

References