skip to content

Authoring and Fixtures

The structural pieces of a Go test file that outlive the assertion: t.Parallel ordering, fixtures under testdata/ and golden files a flag regenerates. This is where table tests break.

part ofGo (Golang)overview, primer and where to startread it →
on this pageshow

explore

questions

page 2 of 2

A pull request adds a green test asserting reflect.DeepEqual(got, want) on a result struct - why might it prove nothing?

level: seniorimportance: nice to knowfreq 30%

basics

~20 s

A green whole-struct comparison proves nothing when want came from the same code path, or when both sides are zero values and every field trivially matches. It can also over-constrain, breaking on fields the case never meant to pin.

open as a page

Reviewing a PR that regenerates a 400-line golden file under testdata, what do you check before approving?

level: seniorimportance: nice to knowfreq 26%

basics

~20 s

Read the diff, because a run with -update writes the file it then compares and cannot fail. Check that every hunk, especially deletions, is explained by the change, and that a plain go test passes on the committed bytes.

open as a page

When has a Go test table's case struct grown too many fields, and what do you do about it?

level: seniorimportance: nice to knowfreq 34%

basics

~20 s

When the loop body branches on flags most rows leave unset, the table describes two behaviours at once. Split it into a second test function, and pick any new field's zero value so existing rows keep their meaning.

open as a page

showing 31–33 of 33