Golden Test
ELI5 — The Vibe Check
Golden tests compare output against a saved "golden" snapshot — when "it looks right" becomes automated and version-controlled. You run the code, approve the output once, and that output becomes the test. Next time it changes, the test fails. It's like taking a photo of something working correctly and using that photo to catch when it stops looking right. Great for rendered HTML, PDF output, API responses, or anything with complex visual structure.
Real Talk
Golden tests (also called approval tests or baseline tests) work by serializing a function's output and comparing it to a stored reference file. Frameworks include Jest's toMatchSnapshot(), Approvaltests.NET, and custom golden file comparators. Unlike assertion-based tests that describe expected values explicitly, golden tests capture the full output — which makes them easy to create but potentially noisy when outputs change legitimately.
When You'll Hear This
"We use golden tests for the PDF generator — any layout change breaks it and flags for review." / "Golden tests found the regression immediately. Without them we'd have shipped broken HTML."
Related Terms
Flaky Test
A flaky test is a test that sometimes passes and sometimes fails for no clear reason — even when nothing changed.
Snapshot Testing
Snapshot testing is taking a picture of your component's output and saving it. Next time tests run, it takes a new picture and compares them.
Test Runner
A test runner is the thing that actually runs your tests and tells you which ones passed and which ones failed.