mao

package module
v0.0.0-...-89ce898 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2014 License: MIT Imports: 9 Imported by: 0

README

Māo

Pragmatic BDD Testing Framework For Go.

import "math"

Desc("math.Abs", func(it It) {
  it("returns the absolute value of x", func(expect Expect) {
    expect(math.Abs(-12)).Equal(12.0)
    expect(math.Abs(-.5)).Equal(0.5)
  })
})

Why Māo?

  • More flexibility: You can locate your tests in any directory.
  • Don't repeat yourself: Māo does the ceremony for you by preprocessing the test module.
  • Minimalistic Output: Māo doesn't have verbose outputs. It'll output short and briefly, will show you what lines fail in case of any error.

Update: Development Status

Install

Install the Go library first;

$ go install github.com/azer/mao

And optionally, install the command-line tool to avoid the boilerplate code: See examples/simple-with-boilerplate.go if you'd like to skip this step

$ curl https://raw.github.com/azer/mao/master/install | sh

Usage

Create a test module anywhere you want and import the code you'd like to test:

import "math/rand" // or: import "github.com/you/repository"

Desc("math.Abs", func(it It) {
  it("returns the absolute value of x", func(expect Expect) {
    expect(math.Abs(-12)).Equal(12.0)
    expect(math.Abs(-.5)).Equal(0.5)
  })
})

And run it with mao command:

$ mao test.go

It'll either output a simple success message that will look like;

Ran 3 tests successfully.

Or some error messages with failing source code lines, like following;

Reference

BDD API

  • Desc
  • It
  • BeforeEach
  • AfterEach

Assertion API

  • Above
  • Equal
  • NotEqual
  • NotExist
  • ResponseBody
  • Lower

Development Status

I recently think of two major changes in the project;

  • Rewriting the preprocesser (bash script) in Go
  • Replacing "desc/it" with "test".

So it'd be looking like;

import "math"

Test("returns the absolute value of x", func(e Expect) {
  expect(math.Abs(-12)).Equal(12.0)
  expect(math.Abs(-.5)).Equal(0.5)
})

At this point, I wouldn't recommend to use Mao. I still have the same goal but it may cause some pain since its preprocesser is not reliable enough.

And since other projects occupy my time nowadays, I'd appreciate pull requests to reach the goals of the project. Thanks for your interest!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Describe func(desc string, wrapper func(It)) = Desc
)

Functions

func AfterEach

func AfterEach(fn BeforeAfterFn)

func BeforeEach

func BeforeEach(fn BeforeAfterFn)

func Desc

func Desc(desc string, wrapper func(It))

func PrintTestSummary

func PrintTestSummary()

Types

type BeforeAfterFn

type BeforeAfterFn func()

type Expect

type Expect func(val interface{}) *Expected

type Expected

type Expected struct {
	Scope *Test
	Value interface{}
}

func (*Expected) Above

func (self *Expected) Above(b interface{})

func (*Expected) Equal

func (self *Expected) Equal(b interface{})

func (*Expected) Lower

func (self *Expected) Lower(b interface{})

func (*Expected) NotEqual

func (self *Expected) NotEqual(b interface{})

func (*Expected) NotExist

func (self *Expected) NotExist()

func (*Expected) ResponseBody

func (self *Expected) ResponseBody(b interface{})

type FailingLine

type FailingLine struct {
	// contains filtered or unexported fields
}

type It

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

type Test

type Test struct {
	Title      string
	Fn         func(Expect)
	BeforeEach BeforeAfterFn
	AfterEach  BeforeAfterFn
}

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(title string)

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