Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. gocrest

gocrest

BSD-3-ClauseGov1.2.1

A Hamcrest-like assertion library for Go providing composable, self-describing matchers for readable tests.

GitHubGitHub
108 stars7 forks0 contributors

What is gocrest?

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.

Target Audience

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.

Value Proposition

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.

Overview

GoCrest - Hamcrest-like matchers for Go

Use Cases

Best For

  • Writing expressive test assertions that read like natural language sentences
  • Creating complex test conditions by combining multiple matchers with logical operators like AllOf and AnyOf
  • Testing asynchronous operations involving channels, readers, or functions with configurable timeouts
  • Validating complex data structures including strings, arrays, maps, and structs with specialized matchers
  • Improving test failure diagnostics with clear, human-readable error messages
  • Leveraging Go generics for type-safe assertions that catch errors at compile time

Not Ideal For

  • Projects minimizing external dependencies or preferring Go's standard testing package without additional libraries
  • Teams already deeply integrated with Testify or other assertion frameworks and unwilling to refactor tests
  • Codebases heavily using complex structs or custom types that require comparison operators, as GoCrest's `is.LessThan` and `is.GreaterThan` matchers don't support them post-generics
  • Developers needing drop-in, simple assertions for quick prototyping without learning matcher composition syntax

Pros & Cons

Pros

Expressive Composable Matchers

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"))`.

Clear Failure Diagnostics

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.

Type Safety with Generics

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.

Asynchronous Testing Support

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.

Cons

Type-Specific Boilerplate

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.

Limited Complex Type Comparisons

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.

Steeper Initial Learning Curve

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.

Frequently Asked Questions

Quick Stats

Stars108
Forks7
Contributors0
Open Issues2
Last commit3 months ago
CreatedSince 2017

Tags

#matcher#test-matchers#unit-testing#tdd#testing#golang#generics#hamcrest#go#assertion-library

Built With

G
Go

Included in

Go169.1k
Auto-fetched 16 hours ago

Related Projects

TestifyTestify

A toolkit with common assertions and mocks that plays nicely with the standard library

Stars26,097
Forks1,799
Last commit3 days ago
KeployKeploy

Open-source platform for creating safe, isolated production sandboxes for API, integration, and E2E testing.

Stars18,341
Forks2,288
Last commit1 day ago
GoConveyGoConvey

Go testing in the browser. Integrates with `go test`. Write behavioral tests in Go.

Stars8,415
Forks558
Last commit2 years ago
testcontainers-gotestcontainers-go

Testcontainers for Go is a Go package that makes it simple to create and clean up container-based dependencies for automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers that should be run as part of a test and clean up those resources when the test is done.

Stars4,927
Forks623
Last commit7 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub