Testing Stable Output Against a Reference File

A reference file records an approved, representative output so accidental formatting or content changes become visible.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Choose something a reader can audit
  2. Review a deliberate update
  3. Make differences attributable to an intended output change
  4. Review expected-file updates as part of behavior changes

Choose something a reader can audit

For a small export, two records including an empty field and a quoted value can exercise meaningful formatting. Keep the file readable as text when that matches the public interface. This develops the idea of capturing output.

Review a deliberate update

If serialization changes, inspect the diff and confirm the new file matches the requested contract. Time stamps or random fields can be supplied as fixed test inputs. See reproducible runs for controlling such dependencies.[1]

Make differences attributable to an intended output change

A report test compares emitted bytes with an approved fixture. If records use an unspecified order or timestamps from the current clock, differences can appear on every run. Control those inputs when they are outside the tested behavior. See stable file processing order.

Fixture input: fixed IDs and dates
Baseline: reviewed output file
Run: generate to a separate path
Compare: report first changed row or byte range

Review expected-file updates as part of behavior changes

Automatically replacing the baseline on failure can bless a defect. Inspect the difference and decide whether the changed bytes are intentional. For structured output with irrelevant formatting, compare parsed values alongside any necessary formatting checks.

References

  1. Python Software Foundation, unittest: Unit Testing Framework ↩