Skip to content

Golden Test

Medium — good to knowTesting

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."

Made with passive-aggressive love by manoga.digital. Powered by Claude.