zen

package module
v0.0.0-...-564f2e0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2014 License: Apache-2.0 Imports: 6 Imported by: 0

README

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)
        }))
    })
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Desc

func Desc(t *testing.T, desc string, wrapper func(It))

func Equal

func Equal(a, b interface{}) bool

func Exist

func Exist(a, b interface{}) bool

func NotEqual

func NotEqual(a, b interface{}) bool

func NotExist

func NotExist(a, b interface{}) bool

func Setup

func Setup(before, after func()) func(fn func(Expect)) func(Expect)

Types

type Expect

type Expect func(val interface{}) *Expectation

type Expectation

type Expectation struct {
	Output formatter
	Value  interface{}
}

func (*Expectation) To

func (self *Expectation) To(desc string, match Matcher, value interface{})
Example
divisibleBy := func(a, b interface{}) bool {
	return a.(int)%b.(int) == 0
}
expect(9).To("be divisible by", divisibleBy, 3)
Output:

func (*Expectation) ToEqual

func (self *Expectation) ToEqual(b interface{})

func (*Expectation) ToExist

func (self *Expectation) ToExist()

func (*Expectation) ToNotEqual

func (self *Expectation) ToNotEqual(b interface{})

func (*Expectation) ToNotExist

func (self *Expectation) ToNotExist()

type It

type It func(title string, fn func(Expect))

type Matcher

type Matcher func(a, b interface{}) bool

type Test

type Test struct {
	T     *testing.T
	Title string
	Fn    func(Expect)
}

func (*Test) PrintError

func (test *Test) PrintError(message string)

func (*Test) PrintFailingLine

func (test *Test) PrintFailingLine(failingLine *failingLine)

func (*Test) PrintTitle

func (test *Test) PrintTitle()

func (*Test) Run

func (test *Test) Run()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL