+0
日增长
9,076
stars
710
forks
99
watchers
732
prs
921
issues
115
releases
README
---
Ginkgo
Ginkgo is a mature testing framework for Go designed to help you write expressive specs. Ginkgo builds on top of Go's testing foundation and is complemented by the Gomega matcher library. Together, Ginkgo and Gomega let you express the intent behind your specs clearly:
go
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
...
)
var _ = Describe("Checking books out of the library", Label("library"), func() {
var library libraries.Library
var book books.Book
var valjean users.User
BeforeEach(func() {
library = libraries.NewClient()
book = &books.Book{
Title: "Les Miserables",
Author: "Victor Hugo",
}
valjean = users.NewUser("Jean Valjean")
})
When("the library has the book in question", func() {
BeforeEach(func(ctx SpecContext) {
Expect(library.Store(ctx, book)).To(Succeed())
})
Context("and the book is available", func() {
It("lends it to the reader", func(ctx SpecContext) {
Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed())
Expect(valjean.Books()).To(ContainElement(book))
Expect(library.UserWithBook(ctx, book)).To(Equal(valjean))
}, SpecTimeout(time.Second 5))
})
Context("but the book has already been checked out", func() {
var javert users.User
BeforeEach(func(ctx SpecContext) {
javert = users.NewUser("Javert")
Expect(javert.Checkout(ctx, library, "Les Miserables")).To(Succeed())
})
It("tells the user", func(ctx SpecContext) {
err := valjean.Checkout(ctx, library, "Les Miserables")
Expect(err).To(MatchError("Les Miserables is currently checked out"))
}, SpecTimeout(time.Second 5))
It("lets the user place a hold and get notified later", func(ctx SpecContext) {
Expect(valjean.Hold(ctx, library, "Les Miserables")).To(Succeed())
Expect(valjean.Holds(ctx)).To(ContainElement(book))
By("when Javert returns the book")
Expect(javert.Return(ctx, library, book)).To(Succeed())
By("it eventually informs Valjean")
notification := "Les Miserables is ready for pick up"
Eventually(ctx, valjean.Notifications).Should(ContainElement(notification))
Expect(valjean.Checkout(ctx, library, "Les Miserables")).To(Succeed())
Expect(valjean.Books(ctx)).To(ContainElement(book))
Expect(valjean.Holds(ctx)).To(BeEmpty())
}, SpecTimeout(time.Second 10))
})
})
When("the library does not have the book in question", func() {
It("tells the reader the book is unavailable", func(ctx SpecContext) {
err := valjean.Checkout(ctx, library, "Les Miserables")
ExpecTop issues
#1278Support for ordered test suite?(E.g. Smoke test suite is first run, then test suite for each components, finally performance test suite)22 comments · 2023-09-26#892Is it possible to write my own decorator?18 comments · 2022-01-26#1108Patterns for managing expensive spec setup17 comments · 2022-12-28#1668Feature Request: Emulate -fd style output12 comments · 2026-06-04#378How to write table driven tests with variable in BeforeEach12 comments · 2017-09-21#1242Same test executed multiple times in parallel on different processes and some of them not at all11 comments · 2023-07-26#1165Need help to run the tests in specific order11 comments · 2023-03-16#1348cannot support multi version of go 10 comments · 2024-02-05
Discussions
#1667How to? InterceptGinkgoFail(ure)?1 comments · 2026-05-18#1660How to correctly HCF (Halt and Catch Fire) with showing the call site of a ginkgo helper when a non-user test visible goroutine catches fire?2 comments · 2026-05-09#1523junit report granularity1 comments · 2025-03-04#1514Multiple test "groupings" - outputs and reports1 comments · 2025-02-07#1508Optimizing integration testing with ginkgo + testcontainers: reducing resource usage by sharing a single container across test suites1 comments · 2025-01-17#1488Making error messages more readable.2 comments · 2024-11-29#1487Testing embedded JavaScript in my headless browser (and a question)4 comments · 2024-11-27#1432Supported Platforms for race flag1 comments · 2024-07-03
Latest release
v2.34.0 v2.34.0 2026-11-02Features - DeferOnFailure registers a callback that runs only when a spec fails - as soon as the failing node returns and before any teardown (JustAfterEach, AfterEach, AfterAll, DeferCleanup) - so it can capture the state teardown is about to destroy. It takes exactly what DeferCleanup takes and shares its scoping: called in BeforeEach/JustBeforeEach/It it covers the spec, in BeforeAll the ordered container, and in BeforeSuite the whole suite. It is also available on GinkgoT(); note that this adds a method to FullGinkgoTInterface, so hand-written implementations of that interface need to ad