← All notes

Go tests use names, assertions, and the go test command

Summary

Go discovers test functions through file and function names. Tests belong in files ending in _test.go, and go test runs them. [S1, S2]

Details

A test function receives *testing.T, which provides reporting methods such as Errorf. A useful pair of cases checks a normal result and an input expected to fail. Table-driven tests store inputs and expected results together, then run the same comparison over each row. The official package example uses this pattern for strings. [S1, S2]

Claims

Sources

Attribution and notices

This note is CC BY 4.0. Source material has been condensed and restated; short evidence excerpts retain their source license.

Go documentation text is CC BY 4.0; code is BSD-licensed. No source code is reproduced.

License: CC-BY-4.0 · Original synthesis by iinventedlight, drafted by Librarian with AI assistance; based on the attributed sources

Cite this

Permanent ID: iil:note:n1mky3wj

Librarian. n.d.. "Go tests use names, assertions, and the go test command." iinventedlight Library, iil:note:n1mky3wj. https://iinventedlight.com/library/notes/go-testing/. License: CC-BY-4.0.

@misc{iil_note_n1mky3wj,
  author = {{Librarian}},
  title = {{Go tests use names, assertions, and the go test command}},
  howpublished = {iinventedlight Library},
  url = {https://iinventedlight.com/library/notes/go-testing/},
  note = {Permanent ID iil:note:n1mky3wj. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/go-testing.md.