BDD testing framework for Go
Go
Latest commit 564f2e0 Aug 30, 2014 @eduncan911 eduncan911 committed with fixing a bdd_test for required 'Test' prefix,
also removing uneeded ()s (go fmt removed it)
Permalink
Failed to load latest commit information.
LICENSE Apache2 LICENSE Jul 11, 2013
README.md example in readme Sep 14, 2013
bdd.go
bdd_test.go fixing a bdd_test for required 'Test' prefix, Sep 2, 2014
formatter.go Revert "Merge pull request #2 from eduncan911/master" Sep 2, 2014
matcher_test.go Revert "Merge pull request #2 from eduncan911/master" Sep 2, 2014
matchers.go Revert "Merge pull request #2 from eduncan911/master" Sep 2, 2014

README.md

Zen

BDD Testing Framework For Go.

go get github.com/pranavraja/zen

Forked from github.com/azer/mao.

Changes in my fork:

  • Print each behaviour as it's being verified
  • Actually fail the testrunner when there are expectation failures
  • Small API changes
  • Allow custom matchers
package zen

import (
    "testing"
    . "github.com/pranavraja/zen"
)

func TestZen(t *testing.T) {
    Desc(t, "zen", func(it It) {
        it("should know when things exist", func(expect Expect) {
            expect("tree").ToExist()
        })
        it("should know when things don't exist", func(expect Expect) {
            expect(nil).ToNotExist()
        })
        it("should know that a thing is equal to itself", func(expect Expect) {
            expect(1).ToEqual(1)
        })
        it("should know when things are different", func(expect Expect) {
            expect(1).ToNotEqual(2)
        })
        it("should be able to learn about new things", func (expect Expect) {
            divisibleBy := func (a, b interface{}) bool {
                return a.(int) % b.(int) == 0
            }
            expect(1).To("be divisible by", divisibleBy, 1)
        })
    })
}

Output

Pass:

Test passed

Fail:

Test failure

Before and After test setup

package zen

import (
    "testing"
    . "github.com/pranavraja/zen"
)

func TestZen(t *testing.T) {
    Desc(t, "before and after", func(it It) {
        count := 0

        before := func() {
          count++
        }

        after := func() {
          count--
        }

        setup := Setup(before, after)

        it("should execute before and after functions", setup(func(expect Expect) {
            expect(count).ToEqual(1)
        }))

        it("should execute before and after functions", setup(func(expect Expect) {
            expect(count).ToEqual(1)
        }))
    })
}