A Hamcrest-like assertion library for Go providing composable, self-describing matchers for readable tests.
GoCrest is a Hamcrest-inspired assertion library for the Go programming language. It enables developers to write expressive, readable, and flexible test assertions using composable matchers that clearly describe expected outcomes, improving test clarity and maintainability compared to traditional assertion methods.
Go developers writing unit and integration tests who want more readable and maintainable test assertions, particularly those familiar with or interested in Hamcrest-style matchers from other languages.
Developers choose GoCrest for its composable matchers that read like natural language, self-describing failure messages that clearly explain test failures, and a generic-based design that provides type safety and catches errors at compile time rather than relying heavily on reflection.
GoCrest - Hamcrest-like matchers for Go
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Matchers can be combined with logical operators like `AllOf` and `AnyOf` to create complex, readable assertions, as shown in the README example with `is.AllOf(is.StringContaining("abc"), is.LessThan("ghi"))`.
Self-describing error messages provide human-readable explanations of test failures, such as outputting 'Expected: value equal to <bye> but: <hi>', making debugging more efficient.
Uses Go generics to reduce reflection reliance, catching type errors at compile time, as highlighted in the v1.1.0 update where matchers were refactored for generic-based design.
Includes matchers for channels, readers, and functions with configurable timeouts via `Eventually` and `Within` helpers, demonstrated in the asynchronous examples for testing non-blocking operations.
Matchers like `has.Length` require separate variants for arrays, strings, and maps (e.g., `has.StringLength`, `has.MapLength`), and map matchers need explicit key-value type declarations, adding verbosity.
Post-generics, `is.LessThan` and `is.GreaterThan` no longer work on complex types due to Go's operator limitations, restricting their use for advanced data validation scenarios.
The need to import multiple packages (`by`, `then`, `is`, `has`) and master matcher composition syntax can be overwhelming compared to simpler assertion libraries like Testify's assert package.