Home

Awesome

GoSpec

GoSpec is a BDD-style testing framework for the Go programming language. It allows writing self-documenting tests/specs, and executes them in parallel and safely isolated.

NOTICE: GoSpec has not been developed for quite some time, but there is a new testing framework called GoConvey which was inspired by GoSpec and does the same things plus much more.

Source code is available at http://github.com/orfjackal/gospec

For discussion, use the golang-nuts mailing list, at least until GoSpec has so many users that it requires its own mailing list. You may also contact GoSpec's developer, Esko Luontola, by email.

Quick Start

First you must have Go installed on your machine, as instructed in Installing Go.

Install and Update

Download GoSpec using the go get tool:

go get "github.com/orfjackal/gospec/src/gospec"

See go help get for more instructions on using the tool.

See "Version History" for any additional upgrade notes.

Sample Project

Make a copy of the hello-world-template directory to get started. You can run its tests with the go test command. All test files must end with _test.go and all specs must be listed in all_specs_test.go.

Running Specs

You can use the go test command to run GoSpec's specs. The integration with gotest requires a couple of lines of boilerplate: you'll need to write a gotest test method, where you list all your specs and call GoSpec. See all_specs_test.go in the examples directory for an example. Also all your specs must be in files whose names end with _test.go.

See gotest's documentation for instructions on how to use gotest.

GoSpec adds one additional parameter to gotest. Use the -print-all parameter to print a list of all specs: go test -print-all Otherwise only the failing specs are printed. The list of all specs can be useful as documentation.

Writing Specs

The following imports are needed. The first imports the gospec.Context interface and the second is needed for using GoSpec's expectation matchers (Equals, IsTrue, IsNil, Not(), Contains etc.) without having to prefix them with the package name. (In a future GoSpec version the matchers will be moved to their own package.)

import "github.com/orfjackal/gospec/src/gospec"
import . "github.com/orfjackal/gospec/src/gospec"

The specs are written as functions which take gospec.Context as a parameter. You can call the methods of Context to declare expectations and nested specs.

For examples on how to write specs, see the files in the examples directory.

<!--- Replace /master/ with /gospec-1.x.x/ before making a release. -->

Version History

1.x.x (2012-xx-xx)

1.3.9 (2012-03-28)

UPGRADE NOTES: Check your imports - when using the go tool they are different than when using the old hand-written Makefiles.

1.3.8 (2011-08-04)

1.3.7 (2011-07-02)

1.3.6 (2011-05-04)

1.3.5 (2011-01-21)

1.3.4 (2010-10-15)

1.3.3 (2010-10-11)

1.3.2 (2010-10-01)

1.3.1 (2010-09-11)

1.3.0 (2010-09-06)

UPGRADE NOTES: If you have written custom matchers, their result parameters' types have changed. Also the error messages are expected to be in a slightly different format. See expectation_syntax_test.go or GoSpec's built-in matchers for examples.

1.2.0 (2010-04-29)

UPGRADE NOTES: In your spec suite, replace r.AddSpec("SomeSpec", SomeSpec) with r.AddSpec(SomeSpec).

1.1.0 (2010-03-08)

UPGRADE NOTES: In all your specs, replace *gospec.Context with gospec.Context in the spec's parameters. Add import . "gospec" to the imports and change every assertion of the old c.Then(x).Should.Equal(y) syntax to use the new c.Expect(x, Equals, y) syntax.

1.0.0 (2009-12-30)

Project Goals

The following are a must, because they enable using specification-style the way I prefer:

The following are nice-to-haves, which make it more pleasant to use the framework:

License

Copyright © 2009-2012 Esko Luontola <http://www.orfjackal.net>
This software is released under the Apache License 2.0.
The license text is at http://www.apache.org/licenses/LICENSE-2.0