Gomega: the matcher library that gives Go tests failure messages worth reading
Ginkgo's Preferred Matcher Library
At a glance
- What is it?
- Onsi's assertion library for Ginkgo and plain Go tests, with eventually and consistently for async behavior and nine sub-libraries for structs, HTTP, subprocesses, buffers, leaks and benchmarks.
- Who is it for?
- Gomega's real contribution is not the assertion, it is the failure message, and the recent numeric fixes in v1.44.0 are a good illustration of why that is worth caring about: `BeNumerically` comparing `-1` as equal to the largest `uint64` is the kind of bug that hides in a test suite for years. Use `Equal` for values, `Eventually` for anything that arrives late, and reach for `gleak` when a test fails intermittently and you suspect a goroutine you never joined.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 2 days ago.
- What is it written in?
- Mainly Go, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 11, 2026, and from our analysis. They are not legal advice.
Editorial analysis
What the README is, and what it is not
Gomega's README is short, and it says so itself: jump straight to the docs to learn about Gomega, including a list of all available matchers. Everything else is pointers. That is unusual for a library with 2,357 stars and 304 forks, and it tells you something about where the author thinks the documentation belongs.
The identity is in the tagline: Ginkgo's preferred matcher library. Gomega is the assertion half of a two library pair. Ginkgo is the BDD test framework for Go, providing the spec structure and the run orchestration, and Gomega provides the matchers you assert with. They are developed together by the same author and versioned in step, which is why `go.mod` requires `github.com/onsi/ginkgo/v2` directly.
The critical thing to know is that Gomega is not tied to Ginkgo. It registers its matchers with the global `RegisterFailHandler`, so you can use the same `Expect` calls in a plain `go test` function if you wire that handler yourself. Plenty of projects do exactly that: Ginkgo for structure, or not at all, with Gomega purely for the assertion vocabulary.
The project is MIT licensed, was last pushed on 2026-09-24, and reports 47 open issues against those stars, which is a normal ratio for a library of this age and adoption.
Eventually and Consistently are the reason to use it
Two matchers distinguish Gomega from a plain comparison, and they exist because distributed and asynchronous Go code cannot be tested by asserting immediately.
`Eventually` polls a function until it succeeds or times out, which is how you test anything involving a goroutine, a channel, a network call or a database write. The failure message when it times out is the part that matters: instead of `expected true, got false`, you get the last observed values and how long it waited. In a test suite full of timing dependent code, that difference is the difference between a five minute debugging session and a five minute one.
`Consistently` is the mirror image and less commonly used but no less useful. It asserts that something *stays* true for a duration, which is how you verify that a value does not change, that no error appears, or that a callback is not invoked more often than expected. Polling a condition for a while and finding it stable is a genuinely different test from polling for a condition to become true, and most assertion libraries offer only the latter.
Together these two cover the majority of flaky Go tests. The design is worth contrasting with the alternative, which is writing sleep calls and hoping. A sleep is a guess about timing that passes on a fast machine and fails on a slow one, and it is the single largest source of intermittent failures in Go test suites. `Eventually` replaces the guess with a condition and a deadline, which is both faster on success and more informative on failure.
Nine sub-libraries, each solving a specific testing problem
The repository tree is the best documentation of Gomega's scope. Beyond the core `matchers/` directory and the top level `matchers.go` and `gomega_dsl.go`, there are nine separate sub-libraries, each its own directory with its own focus.
go 1.25.0
require (
github.com/google/go-cmp v0.7.0
github.com/onsi/ginkgo/v2 v2.32.0
)`gstruct` is the one you will use soonest. It lets you assert on unexported struct fields, which the standard reflect based matchers cannot reach, and it can ignore specific fields while checking the rest. For a config struct with ten fields where one is a timestamp, that is the difference between a readable test and a brittle one.
`ghttp` is an HTTP test server with fluent request and response matchers, so you assert on what your handler received and what it returned rather than writing the request by hand. `gexec` runs an external command and streams its output for assertions, which is how you test a CLI. `gbytes` does the same for a buffer, including async reads, which is how you test a streaming decoder.
`gleak` is the interesting one for flaky test debugging. Goroutine leaks in Go are silent: the program does not crash, the test suite just gets slower and eventually times out, and the failure points at the wrong test. `gleak` asserts that no unexpected goroutines are running, turning a mysterious intermittent timeout into a specific failure that names the goroutine. `gmeasure` is for benchmarks inside tests, so you can assert that an operation stays under a budget rather than eyeballing benchmark output.
Also present are `gcustom` for registering your own matchers with the same failure message quality, `format/` for the failure message rendering, `types/` for shared types, and `extensions/` for the optional matchers the README mentions as living on the community wiki.
Numeric comparison bugs fixed in the latest release
The most recent release, v1.44.0, is worth reading in detail because it is a masterclass in the kind of bug an assertion library must not have. Every change in it concerns `BeNumerically`, and the headline is that it now compares signed and unsigned integers by value: `-1` no longer equals `uint64(math.MaxUint64)`, and `uint(5)` is now correctly greater than `-3`.
That first fix is the alarming one. A test asserting equality between a signed `-1` and the largest unsigned value was passing, because both wrapped to the same underlying representation and the comparison was not value based. Any suite using `BeNumerically` across signed and unsigned types was asserting something false and getting a green check.
The other entries in the same release are overflow fixes in the `~` comparison, which computes the distance between two integers to decide whether they are approximately equal. With extreme values that subtraction overflows, and an overflowed distance silently becomes either a match or a mismatch depending on the values. A third change addresses `BeNumerically("==")` in the same family.
This is the strongest argument for using a mature assertion library rather than comparing values by hand. These bugs were not in your application logic; they were in the thing you trusted to check your application logic, and they were silent. The library is MIT licensed with a `CHANGELOG.md`, a `RELEASING.md` describing the release process, and a `CONTRIBUTING.md`, and the fixes arrived as tagged commits with issue numbers attached, so the reasoning is traceable.
Dependencies, toolchain and a Claude Code plugin
The dependency list is short and tells you about the scope. `go.mod` declares `go 1.25.0`, so this is a modern toolchain requirement, and it requires `go-cmp` from Google for the diffing that makes failure messages readable, `ginkgo/v2` as the peer, `go.yaml.in/yaml/v3`, `golang.org/x/net`, and `google.golang.org/protobuf`.
Those last two are the interesting ones. `golang.org/x/net` is there for the HTTP sub-library, and protobuf support means Gomega can match on protobuf messages with field level diffs rather than byte equality. Both are optional in practice for most users, pulled in for `ghttp` and protobuf-aware matchers, which is a reasonable trade for a small fixed dependency set.
The repository also has a `.claude-plugin/` directory and a README section on using Gomega with Claude Code. Gomega ships as a plugin marketplace so an agent writing assertions in your suite has the matcher catalog, `Eventually` and `Consistently`, and the sub-libraries available while it writes tests. From inside Claude Code it installs with two commands:
/plugin marketplace add onsi/gomega
/plugin install gomega@gomegaThe README also gives non-interactive equivalents for CI or a scripted setup.
It is an unusual thing for a Go testing library to ship, and it says something about where the maintainer expects more and more code to be written. A `.devcontainer/` directory and a `scripts/` directory sit alongside it, and CI runs from a `test.yml` workflow badged in the README. Worth noting the plugin installs skills describing Gomega's idioms; it does not execute your tests, so a generated assertion still has to be reviewed by whoever owns the suite.
One dependency carries its own licence
The licence section at the bottom of the README is worth reading for a reason that has nothing to do with lawyers. It states that Gomega is MIT licensed, and then it makes an exception: the `ConsistOf` matcher uses a library called goraph, which is embedded in the source to simplify distribution and is itself MIT licensed.
That is a good practice and a rare one. Embedding a dependency rather than requiring it means the module graph stays small, which for a library that every Go test suite in a codebase pulls in actually matters. The cost is that you inherit the code and its maintenance, and the `ConsistOf` matcher inherits goraph's bugs.
So the full answer to what Gomega pulls into your binary is: Gomega, plus a graph library for unordered collection comparison, plus whatever you enable by using `ghttp` or the protobuf matchers. None of it is large, and all of it is permissively licensed, which is why this library ends up in dependency trees that have not been audited in years without anyone complaining.
The community matchers, meanwhile, are not vendored. The README points to a wiki page collecting matchers contributed by users, which is the right place for the long tail of domain specific assertions, and the `extensions/` directory in the tree is where the ones the project considers stable enough to keep live.
Editorial conclusion
Gomega's real contribution is not the assertion, it is the failure message, and the recent numeric fixes in v1.44.0 are a good illustration of why that is worth caring about: `BeNumerically` comparing `-1` as equal to the largest `uint64` is the kind of bug that hides in a test suite for years. Use `Equal` for values, `Eventually` for anything that arrives late, and reach for `gleak` when a test fails intermittently and you suspect a goroutine you never joined. The README will not teach you the matchers, the documentation site will, and it is worth an hour of your time before you write your first spec.
Frequently asked questions
What is Gomega and how does it relate to Ginkgo?
Gomega is the matcher library for Go tests, described as Ginkgo's preferred matcher library. Ginkgo provides the BDD spec structure and Gomega provides the assertions, and they are versioned together, though Gomega can also be used with plain go test functions.
What is the difference between Eventually and Consistently in Gomega?
Eventually polls until a condition becomes true or times out, which is how you test asynchronous and distributed behavior. Consistently polls for a duration to verify a condition stays true, which catches unexpected state changes and unexpected callback invocations.
What are Gomega's sub-libraries for?
Each is a separate directory with its own purpose: gstruct matches unexported struct fields, ghttp is a fluent HTTP test server, gexec asserts on external command output, gbytes on buffer reads, gleak detects leaked goroutines, and gmeasure benchmarks inside tests.
How do I use Gomega with Claude Code?
The repository doubles as a plugin marketplace. Run /plugin marketplace add onsi/gomega then /plugin install gomega@gomega from inside Claude Code, which installs gomega skills that cover the matcher catalog, Eventually and Consistently, and the sub-libraries.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/onsi-gomega)