Categorygithub.com/rsms/go-testutil
repositorypackage
0.1.1
Repository: https://github.com/rsms/go-testutil.git
Documentation: pkg.go.dev

# README

Simple test helper for go

GitHub tag (latest SemVer) PkgGoDev Go Report Card

Synopsis

type Assert struct { T *testing.T }
func NewAssert(t *testing.T) Assert
func (a Assert) Eq(assertionfmt string, value1, value2 interface{}, v ...interface{}) bool
func (a Assert) Err(assertionfmt, errsubstr string, err error, v ...interface{}) bool
func (a Assert) NoErr(assertionfmt string, err error, v ...interface{}) bool
func (a Assert) Ok(assertionfmt string, ok bool, v ...interface{}) bool
func (a Assert) Panic(expectedPanicRegExp string, f func()) bool
func RecoverAsFail(t *testing.T)
func Repr(v interface{}) string

Examples

func TestFoo(t *testing.T) {
  assert := testutil.NewAssert(t)
  assert.Eq("Foo does the expected thing", Foo(), "bar")
}

RecoverAsFail catches a panic and converts it into a test failure

func TestThing(t *testing.T) {
  defer testutil.RecoverAsFail(t)
  somethingThatMayPanic()
}