prettytest: github.com/remogatto/prettytest Index | Files | Directories

package prettytest

import "github.com/remogatto/prettytest"

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/remogatto/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

Package Files

assertions.go formatters.go gocheck.go init.go prettytest.go

Constants

const (
    STATUS_NO_ASSERTIONS = iota
    STATUS_PASS
    STATUS_FAIL
    STATUS_MUST_FAIL
    STATUS_PENDING
)

Variables

var (
    ErrorLog []*Error
)

func Run Uses

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

Run runs the test suites.

func RunWithFormatter Uses

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

Run runs the test suites using the given formatter.

type Assertion Uses

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

type BDDFormatter Uses

type BDDFormatter struct {
    Description string
}

BDDFormatter is a formatter à la rspec.

func (*BDDFormatter) AllowedMethodsPattern Uses

func (formatter *BDDFormatter) AllowedMethodsPattern() string

func (*BDDFormatter) PrintErrorLog Uses

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

func (*BDDFormatter) PrintFinalReport Uses

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

func (*BDDFormatter) PrintStatus Uses

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

func (*BDDFormatter) PrintSuiteInfo Uses

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

type Error Uses

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

type FinalReport Uses

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

func (*FinalReport) Total Uses

func (r *FinalReport) Total() int

type Formatter Uses

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 Uses

type Suite struct {
    T             T
    Package, Name string
    TestFuncs     map[string]*TestFunc
}

func (*Suite) Check Uses

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 Uses

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

Equal asserts that the expected value equals the actual value.

func (*Suite) Error Uses

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

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

func (*Suite) Failed Uses

func (s *Suite) Failed() bool

Failed checks if the test function has failed.

func (*Suite) False Uses

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

Not asserts the given assertion is false.

func (*Suite) MustFail Uses

func (s *Suite) MustFail()

MustFail marks the current test function as an expected failure.

func (*Suite) Nil Uses

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

Nil asserts that the value is nil.

func (*Suite) Not Uses

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

Not asserts the given assertion is false.

func (*Suite) Path Uses

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

Path asserts that the given path exists.

func (*Suite) Pending Uses

func (s *Suite) Pending()

Pending marks the test function as pending.

func (*Suite) True Uses

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

True asserts that the value is true.

type T Uses

type T interface {
    Fail()
}

type TDDFormatter Uses

type TDDFormatter struct{}

TDDFormatter is a very simple TDD-like formatter.

Legend:

* F - Test Failed

* OK - Test Passed

* EF - An Expected Failure occured

* NA - Not Assertions found

* PE - Pending test

func (*TDDFormatter) AllowedMethodsPattern Uses

func (formatter *TDDFormatter) AllowedMethodsPattern() string

func (*TDDFormatter) PrintErrorLog Uses

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

func (*TDDFormatter) PrintFinalReport Uses

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

func (*TDDFormatter) PrintStatus Uses

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

func (*TDDFormatter) PrintSuiteInfo Uses

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

type TestFunc Uses

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

Directories

PathSynopsis
pta

Package prettytest imports 9 packages (graph) and is imported by 1 packages. Updated 2016-10-21. Refresh now. Tools for package owners.