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
- id: C1 claim: "The _test.go suffix identifies a file as containing tests." source: S1 evidence: "Ending a file's name with _test.go"
- id: C2 claim: "The test framework combines the testing package with go test." source: S2 evidence: "the go test command and the testing package"
- id: C3 claim: "Calling a failure-reporting method marks the test as failed." source: S2 evidence: "the test is considered to have failed"
Sources
- [S1] Add a test. The Go Authors. https://go.dev/doc/tutorial/add-a-test. CC-BY-4.0; license: https://go.dev/doc/copyright. Accessed 2026-11-05.
- [S2] for setting %PATH%.. The Go Authors. https://go.dev/doc/code. CC-BY-4.0; license: https://go.dev/doc/copyright. Accessed 2026-11-05.
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
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.},
}
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.