onsi /ginkgo

A Modern Testing Framework for Go

★ 9,076⑂ 710👁 99⑃ 732● 921▤ 115
GoMITCreated 2013-08-23onsi.github.io/ginkgo/
Download: v2.34.0v2.34.0 ↓2.34.02026-11-02
+0
Daily
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")
            Expec

Top issues

Discussions

Latest release

v2.34.0 v2.34.0 2026-11-02
Features
- 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

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON