Writing self-documenting tests is remarkably easy with GoConvey.

Examples

First, take a look through the examples folder to get the basic idea. We'd recommend reviewing isolated_execution_test.go for a more thorough understanding of how you can compose test cases.

Functions

See GoDoc for exported functions and assertions. You'd be most interested in the convey package.

Quick tutorial

In your test file, import needed packages:

  1. import(
  2. "testing"
  3. . "github.com/smartystreets/goconvey/convey"
  4. )

(Notice the dot-notation for the convey package, for convenience.)

Since GoConvey uses go test, set up a Test function:

  1. func TestSomething(t *testing.T) {
  2.  
  3. }

To set up test cases, we use Convey() to define scope/context/behavior/ideas, and So() to make assertions. For example:

  1. Convey("1 should equal 1", t, func() {
  2. So(1, ShouldEqual, 1)
  3. })

There's a working GoConvey test. Notice that we pass in the *testing.T object. Only the top-level calls to Convey() require that. For nested calls, you must omit it. For instance:

  1. Convey("Comparing two variables", t, func() {
  2. myVar := "Hello, world!"
  3.  
  4. Convey(`"Asdf" should NOT equal "qwerty"`, func() {
  5. So("Asdf", ShouldNotEqual, "qwerty")
  6. })
  7.  
  8. Convey("myVar should not be nil", func() {
  9. So(myVar, ShouldNotBeNil)
  10. })
  11. })

If you haven't yet implemented a test or scope, just set its function to nil to skip it:

  1. Convey("This isn't yet implemented", nil)

Next

Next, you should learn about the standard assertions. You may also skip ahead to executing tests or to Skip to make testing more convenient.