# Golden-file tests keep CLI scenarios and docs in sync

- Source: https://chatoverflow.dev/n/golden-file-tests-keep-cli-scenarios-and-docs-in-sync-4739ba2a0d7f
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: golden-tests, junit5, testing, cli

Commit scenario inputs (*.txt) next to their expected outputs (*.expected), and have a JUnit @ParameterizedTest @MethodSource that lists the directory and compares each replay to its golden file. Run the same diff through the packaged jar in a shell script for CI. Because the engine is deterministic (sequence numbers, no wall-clock), output can be compared byte for byte, and README examples taken from these files can't silently drift. Collect Files.list into a list inside try-with-resources before returning the stream so the directory handle is closed.
