setup
Fungsinya
Skill ini menunjukkan cara mengatur kerangka kerja tes Ginkgo di proyek Go dari awal. Skill ini ditujukan untuk pengembang yang pertama kali menambahkan tes Ginkgo ke proyek.
Kapan dipakai
- βSaat Anda pertama kali menambahkan tes Ginkgo ke proyek Go.
- βSaat Anda perlu membuat file tes awal untuk sebuah paket Ginkgo.
- βSaat tes Anda yang sudah ada memakai pustaka pengujian yang harus bekerja bersama Ginkgo.
Link skill
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/setup/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
βTolong atur tes Ginkgo di proyek Go saya supaya saya bisa mulai menulisnya.β
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Skill memasang perintah ginkgo dan pustaka-pustakanya, membuat file tes awal, dan menunjukkan cara menghubungkannya ke sistem tes Go standar.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum
Apa itu Gomega?
Gomega adalah pustaka pendamping yang menyediakan pemeriksaan yang dipakai tes Ginkgo untuk memastikan hasil.
Apakah versi Ginkgo harus cocok?
Ya, perintah ginkgo sebaiknya sesuai dengan versi Ginkgo yang tercantum di file go.mod proyek.
Bisakah saya memakai Ginkgo bersama testify atau gomock?
Bisa. Skill menjelaskan cara berbagi kontrol pengujian dengan pustaka tersebut.
Detail
Deskripsi asli dari pembuat
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
Popularitas
- Bintang GitHub
- 9.1k
- Peringkat
- #12307
- Lisensi
- MIT
- Diperbarui
- 9/10/2026
Komentar
- β¦
Skill lain dari repositori ini
ci
9.1kMembantu agent Anda menyiapkan tes Ginkgo untuk integrasi berkelanjutan, dengan flag yang direkomendasikan untuk menangkap penanda fokus atau tertunda yang tertinggal serta tes yang tidak stabil.
debugging-failures
9.1kMembantu agent Anda mencari tahu mengapa tes Ginkgo gagal dengan membaca baris ringkasan dan mengambil tes yang gagal beserta pesannya dari laporan JSON.
decorators
9.1kMembantu agent Anda memakai dekorator tes Ginkgo dengan benar, seperti Serial, Ordered, Label, Focus, dan batas waktu, dengan menjelaskan fungsi masing-masing.
filtering
9.1kMembantu agent Anda menjalankan hanya sebagian tes Ginkgo, memakai pending, skip, focus, label, batasan versi, dan filter file sesuai urutan prioritasnya.
Skill serupa
test-driven-development
311kMengajari agent Anda menulis tes yang gagal dulu, melihatnya gagal, lalu menulis kode terkecil yang lulus, sebelum membangun fitur atau perbaikan apa pun.
verification-before-completion
311kMengajari agent Anda menjalankan pemeriksaan nyata dan membaca keluarannya sebelum menyatakan tugas, perbaikan, atau build sudah selesai atau lulus.
migrate-to-shoehorn
310kMengganti type cast berisiko di file tes Anda dengan pustaka shoehorn, sehingga tes bisa memakai data parsial dan tetap lulus pemeriksaan tipe.