t.Error and t.Fatal
The *testing.T methods that mark a test as failed: the Error forms continue running the test, the Fatal forms stop it immediately.
In more detail
Use t.Errorf for independent checks so one run reports every problem. Use t.Fatalf when later lines cannot make sense, such as when required setup failed or a result is nil. The f versions take a format string like Printf.
Example
t.Fatalf("double returned %d", got)Related terms
- Go testing package — Go's standard library package for writing tests, run by the go test command.
- test function — A Go function whose name starts with Test and which takes a *testing.T, so go test finds and runs it automatically.
- format verb — A placeholder starting with % in a format string, such as %s or %d, that says how to print the matching argument.
Taught in
- The Standard testing Package — Concurrent Systems Programming with Go
- Writing Table Driven Tests — Concurrent Systems Programming with Go
- Containerizing and Testing the Final Build — Concurrent Systems Programming with Go