03 / 04

What makes Go's testing philosophy different from most other languages?

Go's testing is built into the standard library with no external framework required. Tests live alongside source code, table-driven tests are idiomatic, and benchmarks and examples are first-class citizens.

Go testing basics
Go testing philosophy
  1. 1

    No magic: tests are plain Go functions — easy to debug, no annotation processing

  2. 2

    Subtests via t.Run(): independent failure reporting, can run individual cases with -run

  3. 3

    Testdata directory convention: test fixtures in testdata/ are ignored by the build tool

  4. 4

    Testing helpers use t.Helper() to report errors at the call site, not inside the helper

  5. 5

    go test caches results — unchanged packages are not retested, making test suites fast