bdd-testing
BDD Testing
Write Go tests that describe observable, user-facing behavior rather than implementation mechanics. Ginkgo structures specs as readable sentences; Gomega asserts outcomes. The goal is a suite that survives refactoring because it states what the system does, not how it does it.
Process
READ, UNDERSTAND, RESEARCH, REFLECT before writing any spec.
-
Understand the users and their goals. Identify who calls this code and what outcomes they care about. Specs are written from that vantage point, not from the internals.
-
Discover behaviors, not functions. Walk the subject's public surface and list the behaviors a user would notice: "reports the weight in grams", "rejects an empty title", "retries on transient failure". One behavior → one
It. -
Group behaviors into scenarios. Cluster behaviors under
Context/Whenblocks that name the precondition ("when the book has no author"). The nesting should read as a sentence top-down. -
Implement with Ginkgo + Gomega. Use the syntax reference for exact APIs: ./references/ginkgo-syntax.md. Start from the template: ./assets/spec-template.go.
-
Run via
go test. Specs are standard Go test files —go test ./...works with no extra tooling. TheginkgoCLI adds richer output and parallelism.