Jump to the docs to learn more. To start rolling your Ginkgo tests now keep reading!
-
Ginkgo uses Go's
testing
package and can live alongside your existingtesting
tests. It's easy to bootstrap and start writing your first tests -
Structure your BDD-style tests expressively:
- Nestable
Describe
andContext
container blocks BeforeEach
andAfterEach
blocks for setup and teardownIt
blocks that hold your assertionsJustBeforeEach
blocks that separate creation from configuration (also known as the subject action pattern).
- Nestable
-
A comprehensive test runner that lets you:
- Mark specs as pending
- Focus individual specs, and groups of specs, either programmatically or on the command line
- Run your tests in random order, and then reuse random seeds to replicate the same order.
- Break up your test suite into parallel processes for straightforward test parallelization
-
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.
-
ginkgo
: a command line interface with plenty of handy command line arguments for running your tests and generating test files.The
ginkgo
CLI is convenient, but purely optional -- Ginkgo works just fine withgo test
-
A modular architecture that lets you easily:
- Write custom reporters (for example, Ginkgo comes with a JUnit XML reporter)
- Adapt an existing matcher library (or write your own!) to work with Ginkgo
Gomega: Ginkgo's Preferred Matcher Library
Learn more about Gomega here
You'll need Golang v1.1+ (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
Of course, I heartily recommend Ginkgo and Gomega. Both packages are seeing heavy, daily, production use on a number of projects and boast a mature and comprehensive feature-set.
With that said, it's great to know what your options are :)
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.
There are a number of matcher libraries that have been written to augment Go's built-in XUnit style tests. Here are two that seem to have gained traction:
You can also use Ginkgo's matcher library Gomega in XUnit style tests
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.
Go explore!
Ginkgo is MIT-Licensed