Suppose a nightly report chooses a rate table using a configuration setting and prints the result in local time. A golden file holding only the resulting text cannot tell a rate change from a different timezone. Record the input context next to the expected output.
Build the fixture
Give the test a fixed instant, an explicit timezone, a locale, a working directory and a version of a small synthetic rate table. Record the effective non-secret setting values, including whether a setting was absent. Listing the environment variable names alone leaves the report under-specified. Read the metadata from the same fixture the code received. Avoid copying a real process environment into a test artifact.
Treat ordering as part of the contract until you have a reason to do otherwise. Directory iteration may be arbitrary; a report that promises chronological order should still fail if its rows are reversed. Normalize a generated request identifier only when its value is immaterial. Use the same reviewed normalization rules for both actual and expected output, and compare their version before comparing the payloads.
Test the fixture itself
Run the same case twice in fresh processes. Then advance only the clock across a month boundary. The recorded instant should change in both cases, and the report data should change only where the contract depends on that boundary. Finally, introduce an incorrect rounding result in a disposable copy. If comparison still passes, the masking or the assertions may be hiding a real regression.
Keep the test seam separate from the first behavior change. A stable snapshot is evidence of observed behavior under the recorded conditions, including any existing bug. Document decisions about which observations deserve to become requirements.
This article was created with AI assistance.
Top comments (0)