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/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 ¶
- Constants
- Variables
- func Run(t *testing.T, suites ...tCatcher)
- func RunWithFormatter(t *testing.T, formatter Formatter, suites ...tCatcher)
- type Assertion
- type BDDFormatter
- func (formatter *BDDFormatter) AllowedMethodsPattern() string
- func (formatter *BDDFormatter) PrintErrorLog(logs []*Error)
- func (formatter *BDDFormatter) PrintFinalReport(report *FinalReport)
- func (formatter *BDDFormatter) PrintStatus(testFunc *TestFunc)
- func (formatter *BDDFormatter) PrintSuiteInfo(suite *Suite)
- type Error
- type FinalReport
- type Formatter
- type Suite
- func (s *Suite) Check(obtained interface{}, checker gocheck.Checker, args ...interface{}) *Assertion
- func (s *Suite) Equal(exp, act interface{}, messages ...string) *Assertion
- func (s *Suite) Error(args ...interface{})
- func (s *Suite) Failed() bool
- func (s *Suite) False(value bool, messages ...string) *Assertion
- func (s *Suite) MustFail()
- func (s *Suite) Nil(value interface{}, messages ...string) *Assertion
- func (s *Suite) Not(result *Assertion, messages ...string) *Assertion
- func (s *Suite) Path(path string, messages ...string) *Assertion
- func (s *Suite) Pending()
- func (s *Suite) True(value bool, messages ...string) *Assertion
- type TDDFormatter
- func (formatter *TDDFormatter) AllowedMethodsPattern() string
- func (formatter *TDDFormatter) PrintErrorLog(logs []*Error)
- func (formatter *TDDFormatter) PrintFinalReport(report *FinalReport)
- func (formatter *TDDFormatter) PrintStatus(testFunc *TestFunc)
- func (formatter *TDDFormatter) PrintSuiteInfo(suite *Suite)
- type TestFunc
Constants ¶
const ( STATUS_NO_ASSERTIONS = iota STATUS_PASS STATUS_FAIL STATUS_MUST_FAIL STATUS_PENDING )
Variables ¶
var (
ErrorLog []*Error
)
Functions ¶
func RunWithFormatter ¶
Run runs the test suites using the given formatter.
Types ¶
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 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 ¶
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) Error ¶
func (s *Suite) Error(args ...interface{})
Error logs an error and marks the test function as failed.
func (*Suite) MustFail ¶
func (s *Suite) MustFail()
MustFail marks the current test function as an expected failure.
type TDDFormatter ¶
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 ¶
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)