A simple Go library for snapshot testing that automatically compares test outputs against committed snapshots.
Cupaloy is a Go library that simplifies snapshot testing by automatically capturing test outputs and comparing them against stored snapshots. It eliminates the need for manual snapshot file management, making it easy to detect unintended changes in test results. The library uses go-spew to deeply pretty-print and support almost all basic Go types, ensuring deterministic output validation.
Go developers who write tests and need to verify that outputs remain consistent over time, particularly those working on projects with complex data structures like parsers, APIs, or data transformation pipelines. It is also suitable for developers using table-driven tests who want to automate snapshot comparisons for multiple test cases.
Developers choose Cupaloy over alternatives because it automates snapshot file management entirely, requiring no manual handling of snapshot files. Its integration with go-spew provides wide type support for slices, maps, and nested structs, and it ensures reliability by detecting non-deterministic changes like timestamps, making snapshot testing straightforward and error-resistant.
Simple Go snapshot testing
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Cupaloy automatically finds and updates snapshot files based on test names, as stated in the README, eliminating manual file handling entirely.
Uses go-spew to deeply pretty-print and support almost all basic Go types, including slices, maps, and nested structs, making it versatile for complex data structures.
Detects and fails tests for non-deterministic changes like timestamps, ensuring reliability by preventing false positives from variable data.
Seamlessly works with table-driven tests by capturing snapshots for each subtest case, as demonstrated in the examples with subtests.
Allows customization of snapshot directories via configuration options like SnapshotSubdirectory, enabling organized test data management.
The README admits that functions and channels cannot be fully pretty-printed, limiting snapshot testing for code involving these specific types.
Debugging section highlights that git on Windows can cause line-ending problems, requiring extra configuration and potentially leading to incorrect test failures.
Relies on go-spew for output formatting, which might not match user preferences and could introduce performance overhead or inflexibility.
Updating snapshots requires setting the UPDATE_SNAPSHOTS environment variable, which is less intuitive than command-line flags or integrated tools.