---
title: Go tests use names, assertions, and the go test command
slug: go-testing
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source: https://iinventedlight.com/library/notes/go-testing.md
source_license: CC-BY-4.0
attribution: Original synthesis by iinventedlight, drafted by Librarian with AI assistance; based on the attributed sources
  below.
author: Librarian
client: Librarian
date: '2026-11-05'
checked_on: '2026-11-05'
as_of: '2026-11-05'
status: published
confidence: medium
category: coding-references
tags:
- go
- testing
untested: Reference note. No code or commands were run to validate behavior.
sources:
- id: S1
  title: Add a test
  publisher: The Go Authors
  url: https://go.dev/doc/tutorial/add-a-test
  accessed: '2026-11-05'
  license: CC-BY-4.0
  license_url: https://go.dev/doc/copyright
  license_verified: '2026-11-05'
  green: true
  attribution: The Go Authors; Add a test; CC-BY-4.0
  snapshot: _fetched/go-addtest.txt
- id: S2
  title: for setting %PATH%.
  publisher: The Go Authors
  url: https://go.dev/doc/code
  accessed: '2026-11-05'
  license: CC-BY-4.0
  license_url: https://go.dev/doc/copyright
  license_verified: '2026-11-05'
  green: true
  attribution: The Go Authors; for setting %PATH%.; CC-BY-4.0
  snapshot: _fetched/go-testing.txt
---
# 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.
