prettytest

package module
v0.0.0-...-4153432 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2013 License: MIT Imports: 10 Imported by: 0

README

What's that?

PrettyTest is a simple testing library without bells & whistles that produces pretty outputs.

PrettyTest

Features

PrettyTest main features are:

  • A simple assertion vocabulary for better readability
  • Customizable formatters through interfaces
  • It's integrated with the go test command
  • It can use gocheck checkers (experimental)
  • It has pretty and colorful output with reports

Quick start

package foo

import (
	"github.com/remogatto/prettytest"
	"testing"
)

// Start of setup
type testSuite struct {
	prettytest.Suite
}

func TestRunner(t *testing.T) {
	prettytest.RunWithFormatter(
		t,
		new(prettytest.TDDFormatter),
		new(testSuite),
	)
}
// End of setup


//your tests start here
func (t *testSuite) TestTrueIsTrue() {
	t.True(true)
}

func (t *testSuite) TestEquality() {
	t.Equal("awesome", "awesome")
}

func (t *testSuite) TestNegation() {
	t.Not(t.Equal("awesome", "not good"))
}


//failing test

func (t *testSuite) TestInequality() {
	t.Equal("awesome", "pretty")
}

Then, to run the tests simply use the the go test command:

$ go test

testSuite:
	OK	TestComposition               (2 assertion(s))
	OK	TestEquality                  (1 assertion(s))
	F	TestInequality                (1 assertion(s))
	OK	TestTrueIsTrue                (1 assertion(s))

4 tests, 3 passed, 1 failed, 0 pending, 0 with no assertions
--- FAIL: TestRunner (0.00 seconds)
prettytest.go:453: 	Expected awesome to be not equal to awesome -- /home/andrea/src/sandbox/go/prettytest/example_test.go:39
		
FAIL
exit status 1
FAIL	_/home/andrea/src/sandbox/go/prettytest	0.014s

PrettyAutoTest

PrettyAutoTest is a command that continously watches for changes in your source directory and - in case - re-executes the tests. PrettyAutoTest promotes an agile development approach: write tests, write the implementation that satisfies the tests, have an immediate visual feedback about your progress.

Check this video: http://youtu.be/B35N6q3sveQ

In order to install PrettyAutoTest simply type:

$ go get -v github.com/remogatto/prettytest/pta/

Then simply launch the pta command move in your working directory and type:

$ pta

Type pta -h for additional help.

LICENSE

Copyright (c) 2013 Andrea Fazzi

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

PrettyTest is a simple testing library for golang. It aims to simplify/prettify testing in golang.

It features:

* a simple assertion vocabulary for better readability

* customizable formatters through interfaces

* before/after functions

* integrated with the go test command

* pretty and colorful output with reports

This is the skeleton of a typical prettytest test file:

    package foo

    import (
	"testing"
	"github.com/aarondl/prettytest"
    )

    // Start of setup
    type testSuite struct {
	prettytest.Suite
    }

    func TestRunner(t *testing.T) {
	prettytest.Run(
		t,
		new(testSuite),
	)
    }
    // End of setup

    // Tests start here
    func (t *testSuite) TestTrueIsTrue() {
	t.True(true)
    }

See example/example_test.go and prettytest_test.go for comprehensive usage examples.

Index

Constants

View Source
const (
	STATUS_NO_ASSERTIONS = iota
	STATUS_PASS
	STATUS_FAIL
	STATUS_MUST_FAIL
	STATUS_PENDING
)

Variables

View Source
var (
	ErrorLog []*Error
)

Functions

func Run

func Run(t *testing.T, suites ...tCatcher)

Run runs the test suites.

func RunWithFormatter

func RunWithFormatter(t *testing.T, formatter Formatter, suites ...tCatcher)

Run runs the test suites using the given formatter.

Types

type Assertion

type Assertion struct {
	Line         int
	Name         string
	Filename     string
	ErrorMessage string
	Passed       bool
	// contains filtered or unexported fields
}

type BDDFormatter

type BDDFormatter struct {
	Description string
}

BDDFormatter is a formatter à la rspec.

func (*BDDFormatter) AllowedMethodsPattern

func (formatter *BDDFormatter) AllowedMethodsPattern() string

func (*BDDFormatter) PrintErrorLog

func (formatter *BDDFormatter) PrintErrorLog(logs []*Error)

func (*BDDFormatter) PrintFinalReport

func (formatter *BDDFormatter) PrintFinalReport(report *FinalReport)

func (*BDDFormatter) PrintStatus

func (formatter *BDDFormatter) PrintStatus(testFunc *TestFunc)

func (*BDDFormatter) PrintSuiteInfo

func (formatter *BDDFormatter) PrintSuiteInfo(suite *Suite)

type Error

type Error struct {
	Suite     *Suite
	TestFunc  *TestFunc
	Assertion *Assertion
}

type FinalReport

type FinalReport struct {
	Passed, Failed, ExpectedFailures, Pending, NoAssertions int
}

func (*FinalReport) Total

func (r *FinalReport) Total() int

type Formatter

type Formatter interface {
	PrintSuiteInfo(suite *Suite)
	PrintStatus(testFunc *TestFunc)
	PrintFinalReport(report *FinalReport)
	PrintErrorLog(errorLog []*Error)

	// AllowedMethodPattern returns a regexp for the allowed
	// method name (e.g. "^Test.*" for the TDDFormatter)
	AllowedMethodsPattern() string
}

Formatter is the interface each formatter should implement.

type Suite

type Suite struct {
	T         *testing.T
	Name      string
	TestFuncs map[string]*TestFunc
}

func (*Suite) Check

func (s *Suite) Check(obtained interface{}, checker gocheck.Checker, args ...interface{}) *Assertion

Check wraps gocheck.Check method. It verifies if the first value matches with the expected value. What matching means is defined by the provided checker. In case they do not match, an error will be logged, the test will be marked as failed, and the test execution will continue. Some checkers may not need the expected argument (e.g. IsNil). In either case, any extra arguments provided to the function will be logged next to the reported problem when the matching fails. This is a handy way to provide problem-specific hints. (taken from gocheck doc)

func (*Suite) Equal

func (s *Suite) Equal(exp, act interface{}, messages ...string) *Assertion

Equal asserts that the expected value equals the actual value.

func (*Suite) Error

func (s *Suite) Error(args ...interface{})

Error logs an error and marks the test function as failed.

func (*Suite) Failed

func (s *Suite) Failed() bool

Failed checks if the test function has failed.

func (*Suite) False

func (s *Suite) False(value bool, messages ...string) *Assertion

Not asserts the given assertion is false.

func (*Suite) MustFail

func (s *Suite) MustFail()

MustFail marks the current test function as an expected failure.

func (*Suite) Nil

func (s *Suite) Nil(value interface{}, messages ...string) *Assertion

Nil asserts that the value is nil.

func (*Suite) Not

func (s *Suite) Not(result *Assertion, messages ...string) *Assertion

Not asserts the given assertion is false.

func (*Suite) Path

func (s *Suite) Path(path string, messages ...string) *Assertion

Path asserts that the given path exists.

func (*Suite) Pending

func (s *Suite) Pending()

Pending marks the test function as pending.

func (*Suite) True

func (s *Suite) True(value bool, messages ...string) *Assertion

True asserts that the value is true.

type TDDFormatter

type TDDFormatter struct{}

TDDFormatter is a very simple TDD-like formatter.

func (*TDDFormatter) AllowedMethodsPattern

func (formatter *TDDFormatter) AllowedMethodsPattern() string

func (*TDDFormatter) PrintErrorLog

func (formatter *TDDFormatter) PrintErrorLog(logs []*Error)

func (*TDDFormatter) PrintFinalReport

func (formatter *TDDFormatter) PrintFinalReport(report *FinalReport)

func (*TDDFormatter) PrintStatus

func (formatter *TDDFormatter) PrintStatus(testFunc *TestFunc)

func (*TDDFormatter) PrintSuiteInfo

func (formatter *TDDFormatter) PrintSuiteInfo(suite *Suite)

type TestFunc

type TestFunc struct {
	Name, CallerName string
	Status           int
	Assertions       []*Assertion
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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