setup
Ce qu’il fait
Ce skill montre comment mettre en place le framework de tests Ginkgo dans un projet Go depuis le début. Il s'adresse aux développeurs qui ajoutent pour la première fois des tests Ginkgo à un projet.
Quand l’utiliser
- ✓Lorsque vous ajoutez pour la première fois des tests Ginkgo à un projet Go.
- ✓Quand vous devez créer le fichier de test de départ d'un paquet Ginkgo.
- ✓Quand vos tests existants utilisent une bibliothèque de test qui doit fonctionner avec Ginkgo.
Lien du skill
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/setup/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Mets en place des tests Ginkgo dans mon projet Go pour que je puisse commencer à les écrire.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
Le skill installe la commande ginkgo et les bibliothèques, crée le fichier de test de départ et montre comment le relier au système de tests standard de Go.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis GitHub.
Wiring Ginkgo into a suite
The one-time setup. For the mental model see ginkgo:overview; to start authoring see ginkgo:writing-specs. Docs: https://onsi.github.io/ginkgo/#getting-started.
1. Install the CLI and the libraries
go install github.com/onsi/ginkgo/v2/ginkgo # the `ginkgo` CLI binary → $GOBIN (put it on $PATH)
go get github.com/onsi/gomega/... # the Gomega matcher library
ginkgo version confirms the install. The CLI version must match the github.com/onsi/ginkgo/v2 version in your go.mod — re-run go install ... from the package to sync them. The current major version is v2; everything here assumes it. In CI, sidestep version drift by invoking the CLI via go run github.com/onsi/ginkgo/v2/ginkgo (→ ginkgo:ci).
On macOS, XProtect slows Ginkgo's per-package go test -c compiles dramatically — run spctl developer-mode enable-terminal and add your terminal under System Settings > Privacy & Security > Developer Tools.
2. Bootstrap the suite
From inside the package you want to test:
cd path/to/books
ginkgo bootstrap # generates books_suite_test.go
package books_test
import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
func TestBooks(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Books Suite")
}
What each line buys you:
func TestBooks(t *testing.T)is the singlego testentry point. CallRunSpecsexactly once per process — Ginkgo errors if you call it twice (a niche multi-suite-per-process escape hatch exists viaextensions/globals.Reset(), seeginkgo:running).RegisterFailHandler(Fail)is the one line of glue connecting Gomega to Ginkgo: it tells Gomega to call Ginkgo'sFailon a failed assertion. Without dot-imports this readsgomega.RegisterFailHandler(ginkgo.Fail).RunSpecs(t, "Books Suite")builds the spec tree and runs it; let it drive*testing.Tfor you.
3. The _test package convention — and what it forces
ginkgo bootstrap puts the suite in package books_test, not package books. Go specially permits a *_test package to live in the same directory as the package it tests, compiled as a separate package. The consequence: your suite has no access to books's unexported internals — it must import and exercise the external API. That's deliberate, nudging you to test behavior, not implementation. (You may use plain package books for true white-box unit tests when you need the internals.)
4. Dot-imports and the alternatives
Ginkgo and Gomega are DSLs, so the docs dot-import both into the suite's namespace to read naturally. Recommend this strongly to the user. If they'd rather keep the global namespace clean:
- Alias the whole DSL (slight
g.stutter everywhere):import g "github.com/onsi/ginkgo/v2" var _ = g.Describe("Books", func() { g.It("works", func() {}) }) - Mix-and-match the
dslsubpackages — dot-import the parts you want, namespace the rest:
Available:import ( . "github.com/onsi/ginkgo/v2/dsl/core" // containers, setup, subjects, RunSpecs, By, GinkgoT "github.com/onsi/ginkgo/v2/dsl/decorators" // Label, Ordered, Serial, … ) var _ = It("core dot-imported", decorators.Label("namespaced decorator"), func() {})dsl/core,dsl/decorators,dsl/reporting(ReportAfterEach,AddReportEntry, …),dsl/table(DescribeTable,Entry). They re-export from the root package — no behavioral difference, purely namespacing. ginkgo bootstrap --nodotgenerates a no-dot bootstrap to start from.
5. Add spec files
ginkgo generate book # generates book_test.go with a top-level Describe + the books import
You can write specs directly in the suite file, but ginkgo generate <subject> scaffolds a per-file Describe in the same _test package. Now write specs → ginkgo:writing-specs.
6. Third-party libraries that want a *testing.T
Matcher and mocking libraries take a *testing.T (or testing.TB). Ginkgo has no real *testing.T per spec, so pass the seam instead:
GinkgoT()returns a value implementing every*testing.Tmethod — hand it to testify, gomock, etc.GinkgoTB()returns atesting.TB-satisfying wrapper for libraries that demand that interface (reach the inner viaGinkgoTBWrapper.GinkgoT).
assert.Equal(GinkgoT(), foo{}.Name(), "foo") // testify i
Questions fréquentes
Qu'est-ce que Gomega ?
Gomega est une bibliothèque complémentaire qui fournit les vérifications utilisées par les tests Ginkgo pour confirmer les résultats.
Les versions de Ginkgo doivent-elles correspondre ?
Oui, la commande ginkgo doit correspondre à la version de Ginkgo indiquée dans le fichier go.mod du projet.
Puis-je utiliser Ginkgo avec testify ou gomock ?
Oui, le skill explique comment partager les outils de contrôle de test avec ces bibliothèques.
Détails
Description originale de l’auteur
Wire Ginkgo into a Go package — install the ginkgo CLI and Ginkgo+Gomega, ginkgo bootstrap to generate the suite_test.go (TestXxx/RegisterFailHandler(Fail)/RunSpecs), the package xxx_test convention, dot-import alternatives (aliased import, dsl/* subpackages, --nodot), ginkgo generate, and *testing.T interop via GinkgoT()/GinkgoTB() for testify/gomock. Use when first adding Ginkgo to a repo, bootstrapping a suite, or integrating a *testing.T-based library.
repo: onsi/ginkgo
Popularité
- Étoiles GitHub
- 9.1k
- Position au classement
- #12307
- Licence
- MIT
- Mis à jour
- 09/10/2026
Commentaires
- …
Autres skills de ce dépôt
ci
9.1kAide votre agent à configurer les tests Ginkgo pour l'intégration continue, avec des options qui détectent les marqueurs oubliés et les tests instables.
debugging-failures
9.1kAide votre agent à comprendre pourquoi des tests Ginkgo ont échoué, en lisant le résumé et en extrayant les tests et messages exacts d'un rapport JSON.
decorators
9.1kAide votre agent à utiliser correctement les décorateurs de tests Ginkgo, comme Serial, Ordered, Label, Focus et les délais, en expliquant le rôle de chacun.
filtering
9.1kAide votre agent à lancer une partie des tests Ginkgo avec pending, skip, focus, labels et filtres, dans le bon ordre de priorité.
Skills similaires
test-driven-development
311kApprend à votre agent à écrire d'abord un test qui échoue, à le voir échouer, puis à écrire le code minimal qui le fait réussir, avant de construire toute fonctionnalité ou correction.
verification-before-completion
311kApprend à votre agent à lancer de véritables contrôles et à lire leurs résultats avant d'affirmer qu'une tâche, une correction ou une compilation est terminée ou réussie.
migrate-to-shoehorn
310kRemplace les conversions de type risquées dans vos fichiers de test par la bibliothèque shoehorn, afin que les tests utilisent des données partielles et passent les contrôles de types.