assert

package
v0.0.0-...-4682b79 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2015 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

README

assert

GoDoc

assert is Go package that provides convenience methods for writing assertions in standard Go tests.

You can write this test with assert:

func TestSomething(t *testing.T) {
  i, err := doSomething()
  assert.NoErr(err)
  assert.Equal(i, 123, "returned integer")
}

Instead of writing this test with only the standard testing library:

func TestSomething(t *testing.T) {
  i, err := doSomething()
  if err != nil {
    t.Fatalf("error encountered: %s", err)
  }
  if i != 123 {
    t.Fatalf("returned integer was %d, not %d", i, 123)
  }
}

Documentation

Overview

package assert provides convenience assert methods to complement the built in go testing library. It's intended to add onto standard Go tests. Example usage:

func TestSomething(t *testing.T) {
	i, err := doSomething()
	assert.NoErr(err)
	assert.Equal(i, 123, "returned integer")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(t *testing.T, actual, expected interface{}, noun string)

Equal ensures that the actual value returned from a test was equal to an expected. it uses reflect.DeepEqual to do so. name is used to describe the values being compared. it's used in the error string if actual != expected.

func Err

func Err(t *testing.T, expected error, actual error)

Err calls t.Fatalf if expected is not equal to actual. it uses reflect.DeepEqual to determine if the errors are equal

func ExistsErr

func ExistsErr(t *testing.T, err error, noun string)

if err == nil, ExistsErr calls t.Fatalf explaining that the error described by noun was nil when it shouldn't have been

func False

func False(t *testing.T, b bool, fmtStr string, vals ...interface{})

False is the equivalent of True(t, !b, fmtStr, vals...).

func Nil

func Nil(t *testing.T, i interface{}, noun string)

Nil uses reflect.DeepEqual(i, nil) to determine if i is nil. if it's not, Nil calls t.Fatalf explaining that the noun i is not nil when it should have been

func NoErr

func NoErr(t *testing.T, e error)

NoErr calls t.Fatalf if e is not nil.

func NotNil

func NotNil(t *testing.T, i interface{}, noun string)

NotNil uses reflect.DeepEqual(i, nil) to determine if i is nil. if it is, NotNil calls t.Fatalf explaining that the noun i is nil when it shouldn't have been.

func True

func True(t *testing.T, b bool, fmtStr string, vals ...interface{})

True fails the test if b is false. on failure, it calls t.Fatalf(fmtStr, vals...)

Types

This section is empty.

Jump to

Keyboard shortcuts

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