overview
Skill này làm gì
Skill này cho một bức tranh rõ ràng về cách công cụ kiểm thử Ginkgo cho Go hoạt động. Nó dành cho lập trình viên bắt đầu một dự án kiểm thử Ginkgo hoặc lên kế hoạch cho một việc kiểm thử.
Khi nào nên dùng
- ✓Khi bạn bắt đầu làm việc với các bài kiểm thử Ginkgo trong một dự án Go lần đầu.
- ✓Khi bạn cần quyết định cách tiếp cận một việc kiểm thử trong một dự án Ginkgo.
- ✓Khi các bài kiểm thử Ginkgo của bạn hoạt động theo cách bạn không mong đợi.
Liên kết skill
https://github.com/onsi/ginkgo/blob/master/plugins/ginkgo/skills/overview/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Tôi mới dùng Ginkgo cho Go. Bạn có thể giải thích các bài kiểm thử của nó được tổ chức thế nào trước khi chúng ta bắt đầu không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill giải thích rằng Ginkgo trước tiên xây danh sách tất cả các bài kiểm thử rồi mới chạy chúng, và chỉ đến các hướng dẫn khác cho những chủ đề cụ thể.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Ginkgo: the mental model
Ginkgo is an expressive BDD-style testing framework for Go, paired with the Gomega matcher library. You build suites out of nested container nodes (Describe/Context/When) and subject nodes (It), with setup nodes (BeforeEach/AfterEach/…) supplying state. You drive it with the ginkgo CLI. Strongly prefer ginkgo over go test.
Read the canonical narrative docs at https://onsi.github.io/ginkgo/ — they are the source of truth. This skill is the orientation; the other skills go deep.
The one idea: tree construction, then running
Ginkgo runs your suite in two distinct phases. Internalizing this explains nearly every Ginkgo gotcha:
- Tree-construction phase. Ginkgo invokes every container body exactly once to discover the structure of your suite. It collects — but does not run — the closures you pass to setup and subject nodes. The result is a tree it flattens into a list of specs.
- Run phase. Ginkgo walks the flattened spec list (randomized, possibly in parallel) and, for each spec, runs its setup closures, then its one subject closure, then its cleanup closures.
Container bodies run at construction time. Setup/subject closures run later, at run time. The consequences you must internalize:
- No assertions in container bodies. They'd run once during construction, with no spec active — not as part of any test. Put assertions in
ItorBeforeEach. - No initialization in container bodies. A variable set in a
Describebody is set once, shared across every spec, and mutated by whichever spec runs first. Declare in the container, initialize inBeforeEachso every spec gets a pristine copy. →ginkgo:writing-specs. - Loops that build specs run at construction time — that's how you generate specs dynamically, but it also means closure-captured loop variables and any data the loop reads must be available then, not in
BeforeSuite. →ginkgo:tables-and-dynamic-specs.
Spec independence — the assumption everything rests on
Ginkgo assumes every spec is independent. This is what lets it randomize order (--randomize-all), run specs in parallel across processes (-p), and run any subset (--focus/labels). The rule that keeps you honest: declare in container, initialize in setup. Deliberate cross-spec dependencies break randomization and parallelism — when you genuinely need ordering, say so explicitly with an Ordered container (→ ginkgo:ordering-and-flakes) rather than relying on definition order.
The Parallelism Model
Ginkgo's parallelism model is process-based: each process runs a subset of the specs, with no shared memory.
The node taxonomy at a glance
- Containers —
Describe,Context,When(identical; pick the one that reads best). Organize the tree. - Subjects —
It,Specify(identical). The actual test; contains the assertions. - Setup —
BeforeEach/AfterEach(around every spec),JustBeforeEach/JustAfterEach(split configuration from creation),BeforeAll/AfterAll(once perOrderedcontainer),BeforeSuite/AfterSuite(once per suite),SynchronizedBeforeSuite/SynchronizedAfterSuite(for common setup, then per-process setup when parallel).DeferCleanupregisters teardown inline;DeferOnFailureregisters failure-only diagnostics that run before teardown. - Reporting —
ReportAfterEach/ReportAfterSuiteetc. observe results. →ginkgo:reporting. - Decorators — modifiers attached to any node:
Serial,Ordered,Label,Focus,FlakeAttempts,SpecTimeout, … →ginkgo:decorators.
Failures work by panic: Fail (which Gomega calls for you) panics; Ginkgo recovers it, records the failure, and runs cleanup. A goroutine that might fail needs defer GinkgoRecover() or its panic crashes the suite. → ginkgo:timeouts-and-async.
Where to go next
- Wiring Ginkgo into a project (bootstrap,
RunSpecs, the CLI, dot-import alternatives) →ginkgo:setup - Authoring specs (containers, subjects, setup/cleanup, the construction-time pitfalls) →
ginkgo:writing-specs - Table-driven and generated specs (
DescribeTable, shared behaviors) →ginkgo:tables-and-dynamic-specs - Looking up a decorator →
ginkgo:decorators - Running a subset (focus, skip, labels) →
ginkgo:filtering - Running in parallel / integration suites →
ginkgo:parallelism - **Ordered containers and fl
Câu hỏi thường gặp
Ginkgo là gì?
Ginkgo là một framework kiểm thử cho ngôn ngữ lập trình Go, dùng phong cách viết gần giống câu văn dễ đọc.
Skill này có viết kiểm thử giúp tôi không?
Nó cung cấp nền tảng cần thiết để hướng dẫn việc viết kiểm thử, còn các hướng dẫn khác trong cùng bộ sẽ đi sâu vào chi tiết.
Tôi có nên dùng lệnh ginkgo không?
Skill khuyên dùng công cụ dòng lệnh ginkgo thay vì lệnh go test tiêu chuẩn.
Chi tiết
Mô tả gốc của tác giả
The Ginkgo mental model for writing Go tests — the one idea that explains everything (Ginkgo builds a spec tree at construction time, then runs it) and its consequences for how you write specs, plus spec independence and the node taxonomy. Use this first when you start working with Ginkgo in a project, or to decide how to approach a Ginkgo task. Routes to the other ginkgo:* skills.
repo: onsi/ginkgo
Độ phổ biến
- Sao GitHub
- 9.1k
- Vị trí xếp hạng
- #12303
- Giấy phép
- MIT
- Cập nhật
- 9/10/2026
Bình luận
- …
Thêm skill từ kho mã này
ci
9.1kGiúp agent của bạn thiết lập kiểm thử Ginkgo cho CI, với các cờ khuyến nghị để bắt dấu focus hoặc pending còn sót và bài kiểm thử không ổn định.
debugging-failures
9.1kGiúp agent của bạn tìm lý do kiểm thử Ginkgo bị lỗi bằng cách đọc dòng tóm tắt và lấy đúng các bài thất bại cùng thông báo từ báo cáo JSON.
decorators
9.1kGiúp agent của bạn dùng đúng các decorator của kiểm thử Ginkgo, như Serial, Ordered, Label, Focus và timeout, bằng cách giải thích mỗi decorator làm gì.
filtering
9.1kGiúp agent của bạn chỉ chạy một số bài kiểm thử Ginkgo, dùng pending, skip, focus, label, ràng buộc phiên bản và bộ lọc file theo đúng thứ tự ưu tiên.
Skill tương tự
test-driven-development
311kDạy agent của bạn viết kiểm thử thất bại trước, xem nó thất bại, rồi viết đoạn mã ngắn nhất để vượt qua trước khi làm bất kỳ tính năng hay bản sửa nào.
verification-before-completion
311kDạy agent của bạn chạy kiểm tra thực tế và đọc kết quả đầu ra trước khi khẳng định một việc, bản sửa hoặc bản build đã hoàn thành hay vượt qua.
migrate-to-shoehorn
310kThay các ép kiểu rủi ro trong tệp kiểm thử bằng thư viện shoehorn, để các bài kiểm thử dùng dữ liệu một phần vẫn qua được kiểm tra kiểu.