To discuss Ginkgo and get updates, join the google group.
Structure your BDD-style tests expressively:
AfterEachblocks for setup and teardown
Itblocks that hold your assertions
JustBeforeEachblocks that separate creation from configuration (also known as the subject action pattern).
AfterSuiteblocks to prep for and cleanup after a suite.
A comprehensive test runner that lets you:
ginkgo -nodes=Nruns your tests in
Nparallel processes and print out coherent output in realtime
ginkgo -coverruns your tests using Golang's code coverage tool
ginkgo convertconverts an XUnit-style
testingpackage to a Ginkgo-style package
ginkgo -skip="REGEXP"allow you to specify a subset of tests to run via regular expression
ginkgo -rruns all tests suites under the current directory
ginkgo -vprints out identifying information for each tests just before it runs
And much more: run
ginkgo helpfor details!
ginkgoCLI is convenient, but purely optional -- Ginkgo works just fine with
ginkgo watchwatches packages and their dependencies for changes, then reruns tests. Run tests immediately as you develop!
Built-in support for testing asynchronicity
Built-in support for benchmarking your code. Control the number of benchmark samples as you gather runtimes and other, arbitrary, bits of numerical information about your code.
A modular architecture that lets you easily:
- Write custom reporters (for example, Ginkgo comes with a JUnit XML reporter and a TeamCity reporter).
- Adapt an existing matcher library (or write your own!) to work with Ginkgo
Gomega: Ginkgo's Preferred Matcher Library
Ginkgo is best paired with Gomega. Learn more about Gomega here
Agouti: A Golang Acceptance Testing Framework
Agouti allows you run WebDriver integration tests. Learn more about Agouti here
Set Me Up!
You'll need Golang v1.4+ (Ubuntu users: you probably have Golang v1.0 -- you'll need to upgrade!)
go get github.com/onsi/ginkgo/ginkgo # installs the ginkgo CLI go get github.com/onsi/gomega # fetches the matcher library cd path/to/package/you/want/to/test ginkgo bootstrap # set up a new ginkgo suite ginkgo generate # will create a sample test file. edit this file and add your tests then... go test # to run your tests ginkgo # also runs your tests
I'm new to Go: What are my testing options?
With that said, it's great to know what your options are :)
What Golang gives you out of the box
Testing is a first class citizen in Golang, however Go's built-in testing primitives are somewhat limited: The testing package provides basic XUnit style tests and no assertion library.
Matcher libraries for Golang's XUnit style tests
A number of matcher libraries have been written to augment Go's built-in XUnit style tests. Here are two that have gained traction:
BDD style testing frameworks
There are a handful of BDD-style testing frameworks written for Golang. Here are a few:
Finally, @shageman has put together a comprehensive comparison of golang testing libraries.
Ginkgo is MIT-Licensed