1![Ginkgo: A Go BDD Testing Framework](http://onsi.github.io/ginkgo/images/ginkgo.png) 2 3[![Build Status](https://travis-ci.org/onsi/ginkgo.svg?branch=master)](https://travis-ci.org/onsi/ginkgo) 4 5Jump to the [docs](http://onsi.github.io/ginkgo/) to learn more. To start rolling your Ginkgo tests *now* [keep reading](#set-me-up)! 6 7If you have a question, comment, bug report, feature request, etc. please open a GitHub issue. 8 9## Feature List 10 11- Ginkgo uses Go's `testing` package and can live alongside your existing `testing` tests. It's easy to [bootstrap](http://onsi.github.io/ginkgo/#bootstrapping-a-suite) and start writing your [first tests](http://onsi.github.io/ginkgo/#adding-specs-to-a-suite) 12 13- Structure your BDD-style tests expressively: 14 - Nestable [`Describe`, `Context` and `When` container blocks](http://onsi.github.io/ginkgo/#organizing-specs-with-containers-describe-and-context) 15 - [`BeforeEach` and `AfterEach` blocks](http://onsi.github.io/ginkgo/#extracting-common-setup-beforeeach) for setup and teardown 16 - [`It` and `Specify` blocks](http://onsi.github.io/ginkgo/#individual-specs-) that hold your assertions 17 - [`JustBeforeEach` blocks](http://onsi.github.io/ginkgo/#separating-creation-and-configuration-justbeforeeach) that separate creation from configuration (also known as the subject action pattern). 18 - [`BeforeSuite` and `AfterSuite` blocks](http://onsi.github.io/ginkgo/#global-setup-and-teardown-beforesuite-and-aftersuite) to prep for and cleanup after a suite. 19 20- A comprehensive test runner that lets you: 21 - Mark specs as [pending](http://onsi.github.io/ginkgo/#pending-specs) 22 - [Focus](http://onsi.github.io/ginkgo/#focused-specs) individual specs, and groups of specs, either programmatically or on the command line 23 - Run your tests in [random order](http://onsi.github.io/ginkgo/#spec-permutation), and then reuse random seeds to replicate the same order. 24 - Break up your test suite into parallel processes for straightforward [test parallelization](http://onsi.github.io/ginkgo/#parallel-specs) 25 26- `ginkgo`: a command line interface with plenty of handy command line arguments for [running your tests](http://onsi.github.io/ginkgo/#running-tests) and [generating](http://onsi.github.io/ginkgo/#generators) test files. Here are a few choice examples: 27 - `ginkgo -nodes=N` runs your tests in `N` parallel processes and print out coherent output in realtime 28 - `ginkgo -cover` runs your tests using Go's code coverage tool 29 - `ginkgo convert` converts an XUnit-style `testing` package to a Ginkgo-style package 30 - `ginkgo -focus="REGEXP"` and `ginkgo -skip="REGEXP"` allow you to specify a subset of tests to run via regular expression 31 - `ginkgo -r` runs all tests suites under the current directory 32 - `ginkgo -v` prints out identifying information for each tests just before it runs 33 34 And much more: run `ginkgo help` for details! 35 36 The `ginkgo` CLI is convenient, but purely optional -- Ginkgo works just fine with `go test` 37 38- `ginkgo watch` [watches](https://onsi.github.io/ginkgo/#watching-for-changes) packages *and their dependencies* for changes, then reruns tests. Run tests immediately as you develop! 39 40- Built-in support for testing [asynchronicity](http://onsi.github.io/ginkgo/#asynchronous-tests) 41 42- Built-in support for [benchmarking](http://onsi.github.io/ginkgo/#benchmark-tests) your code. Control the number of benchmark samples as you gather runtimes and other, arbitrary, bits of numerical information about your code. 43 44- [Completions for Sublime Text](https://github.com/onsi/ginkgo-sublime-completions): just use [Package Control](https://sublime.wbond.net/) to install `Ginkgo Completions`. 45 46- [Completions for VSCode](https://github.com/onsi/vscode-ginkgo): just use VSCode's extension installer to install `vscode-ginkgo`. 47 48- Straightforward support for third-party testing libraries such as [Gomock](https://code.google.com/p/gomock/) and [Testify](https://github.com/stretchr/testify). Check out the [docs](http://onsi.github.io/ginkgo/#third-party-integrations) for details. 49 50- A modular architecture that lets you easily: 51 - Write [custom reporters](http://onsi.github.io/ginkgo/#writing-custom-reporters) (for example, Ginkgo comes with a [JUnit XML reporter](http://onsi.github.io/ginkgo/#generating-junit-xml-output) and a TeamCity reporter). 52 - [Adapt an existing matcher library (or write your own!)](http://onsi.github.io/ginkgo/#using-other-matcher-libraries) to work with Ginkgo 53 54## [Gomega](http://github.com/onsi/gomega): Ginkgo's Preferred Matcher Library 55 56Ginkgo is best paired with Gomega. Learn more about Gomega [here](http://onsi.github.io/gomega/) 57 58## [Agouti](http://github.com/sclevine/agouti): A Go Acceptance Testing Framework 59 60Agouti allows you run WebDriver integration tests. Learn more about Agouti [here](http://agouti.org) 61 62## Set Me Up! 63 64You'll need the Go command-line tools. Ginkgo is tested with Go 1.6+, but preferably you should get the latest. Follow the [installation instructions](https://golang.org/doc/install) if you don't have it installed. 65 66```bash 67 68go get -u github.com/onsi/ginkgo/ginkgo # installs the ginkgo CLI 69go get -u github.com/onsi/gomega/... # fetches the matcher library 70 71cd path/to/package/you/want/to/test 72 73ginkgo bootstrap # set up a new ginkgo suite 74ginkgo generate # will create a sample test file. edit this file and add your tests then... 75 76go test # to run your tests 77 78ginkgo # also runs your tests 79 80``` 81 82## I'm new to Go: What are my testing options? 83 84Of course, I heartily recommend [Ginkgo](https://github.com/onsi/ginkgo) and [Gomega](https://github.com/onsi/gomega). Both packages are seeing heavy, daily, production use on a number of projects and boast a mature and comprehensive feature-set. 85 86With that said, it's great to know what your options are :) 87 88### What Go gives you out of the box 89 90Testing is a first class citizen in Go, however Go's built-in testing primitives are somewhat limited: The [testing](http://golang.org/pkg/testing) package provides basic XUnit style tests and no assertion library. 91 92### Matcher libraries for Go's XUnit style tests 93 94A number of matcher libraries have been written to augment Go's built-in XUnit style tests. Here are two that have gained traction: 95 96- [testify](https://github.com/stretchr/testify) 97- [gocheck](http://labix.org/gocheck) 98 99You can also use Ginkgo's matcher library [Gomega](https://github.com/onsi/gomega) in [XUnit style tests](http://onsi.github.io/gomega/#using-gomega-with-golangs-xunitstyle-tests) 100 101### BDD style testing frameworks 102 103There are a handful of BDD-style testing frameworks written for Go. Here are a few: 104 105- [Ginkgo](https://github.com/onsi/ginkgo) ;) 106- [GoConvey](https://github.com/smartystreets/goconvey) 107- [Goblin](https://github.com/franela/goblin) 108- [Mao](https://github.com/azer/mao) 109- [Zen](https://github.com/pranavraja/zen) 110 111Finally, @shageman has [put together](https://github.com/shageman/gotestit) a comprehensive comparison of Go testing libraries. 112 113Go explore! 114 115## License 116 117Ginkgo is MIT-Licensed 118 119## Contributing 120 121See [CONTRIBUTING.md](CONTRIBUTING.md) 122