Snapshot tests
In short: A snapshot test stores the output of a piece of the program once as a reference and compares it with the new result on later runs.
In more detail: Instead of checking every value individually, for example the rendered HTML of a component is saved as a file. If the output changes, the test fails and you decide: unintended bug or intended change (then update the snapshot).
In Depth
- Good for: Large, stable outputs such as error messages, serialized data or reports.
- Risk: Huge snapshots get confirmed unread during updates and lose their value.
- Keep small: Capture targeted excerpts rather than whole pages.
- Unstable values: Replace timestamps and random IDs with fixed placeholders beforehand.
- Visual variant: Screenshot comparison detects layout bugs but is sensitive to fonts and rendering differences.
See also: Property-based testing