Go testing

Go's testing package provides the tools for writing and running automated tests. Test functions use the testing.T type to report failures, run subtests, and verify program behavior.

Minimal example

go
func TestAdd(t *testing.T) {
    got := 2 + 3
    if got != 5 {
        t.Fatalf("got %d, want 5", got)
    }
}

Learn this concept

Lesson 1.12 · Go testing: testing.T, subtests and table-driven tests

Used in exercises

Exercise 1.15 · Table-driven tests with a fake clock, plus one race test Exercise 7.18 · Release rollback planner Exercise 8.7 · Benchmark report package Exercise 8.14 · Mermaid sequence linter
Prerequisite conceptsGo functionsGo errors