Golden test file utility.
Golden provides a simple, opinionated API for managing golden test files. See the golden_test.go
and testdata
directory for examples.
package module_test
import (
"testing"
"github.com/dcilke/golden"
)
func Test(t *testing.T) {
actual := functionUnderTest()
golden.Assert(t, actual)
}
- Automatic golden file management. All golden files are stored next to tests in
testdata/golden
. - Automatic naming of golden files. Golden files are named after the test function.See
golden.Subsert()
if multiple asserts are needed in the same test. - Automatic creating golden files if none are present. Golden files can be regenerated by setting the
GOLDEN_UPDATE
environment variable totrue
. - Golden files are serialized with litter to provide clear output and human readable diffs.