# Golden test

> A golden test runs code on a fixed input and compares its output with a stored expected output; any difference fails the test.

A golden test runs code on a fixed input and compares its output with a stored expected output, the "golden" result. Any difference fails the test. Golden tests suit data pipelines because the expected table can be written down exactly, including the hard cases.

For example, a golden test for a deduplication step might use a fixture file of eight customer rows, including two exact duplicates, two versions of one customer with different update times, and a pair with the same update time that needs the tie-breaker. The expected output file lists the five rows that should remain, in a fixed order. The test runs the step on the fixture and compares the result row by row and column by column with the expected file; if one value differs, the test fails and shows the difference.

The value is in the hard cases the fixtures encode: nulls in key columns, records that arrive late, a change that is undone, a batch that is loaded twice. Each is written down once, with its correct result, and checked on every change from then on. A golden test cannot prove a pipeline is right for data nobody thought of, and the expected output is only as good as the person who wrote it, so expected files deserve the same review as code.

Golden tests are also called snapshot or approval tests in other fields. In data engineering they work best on small, deterministic steps whose output can be sorted and compared exactly, which is why they pair well with an engine that starts quickly. See also [idempotency](https://emolysis.com/glossary/idempotency), [pull request check](https://emolysis.com/glossary/pull-request-check) and [template slot](https://emolysis.com/glossary/template-slot).

In Emolysis, every template ships with golden tests, and they run on [DuckDB](https://emolysis.com/glossary/duckdb) on your machine before a pipeline can be deployed; a red result sends the agent back to the template. See [Golden tests on DuckDB](https://emolysis.com/docs/golden-tests). They complement [data quality tests](https://emolysis.com/glossary/data-quality-test), which run on real data.

---

Page: https://emolysis.com/glossary/golden-test. Emolysis is a product of Bandpey GmbH, Munich, Germany. It is in private development, and nothing is released yet.
