assert

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2017 License: MIT Imports: 4 Imported by: 0

README

assert

Ludicrously simple assertion library for Go, just to make using the built-in test a little easier.

Package assert provides some simple but powerful testing helpers. They are designed to greatly simplify testing code, reduce code verbosity, and produce consistent and useful output during tests.

Usage

All assertions take a testing.T instance as the first argument, and will fail the test they're used in if the assertion fails. (They actually accept a much smaller interface than testing.T that makes testing this library much easier).

True

assert.True(t tester, condition bool, message string):

// Take a predicate, and a message to use in the error created for when the predicate is not truthy.
assert.True(t, 1 == 2, "expected 1 to equal 2")
assert.True(t, something.IsTruthy(), "expected something to be truthy")
False

assert.False(t tester, condition bool, message string):

// Take a predicate, and a message to use in the error created for when the predicate is not falsey.
assert.False(t, true == true, "expected true not to equal true")
assert.False(t, something.IsTruthy(), "expected something to be falsey")
Equal

assert.Equal(t tester, expected, actual interface{}):

// Take the expected value, then the actual value, and assert that they are equal.
assert.Equal(t, 1, 1)
assert.Equal(t, 23, mathy.TenPlusThirteen())
Not Equal

assert.NotEqual(t tester, expected, actual interface{}):

// Take the expected value, then the actual value, and assert that they are not equal.
assert.NotEqual(t, 1, 2)
assert.NotEqual(t, 24, mathy.TenPlusThirteen())
OK

assert.OK(t tester, err error):

// Assert the given `error` is nil.
assert.OK(t, something.ThatMayReturnAnError())
Not OK

assert.NotOK(t tester, err error):

// Assert the given `error` is not nil.
assert.OK(t, something.ThatMayReturnAnError())

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Equal

func Equal(t tester, expected, actual interface{})

Equal asserts that the given expected and actual arguments are equal.

func False

func False(t tester, condition bool, message string)

False asserts that the given condition is falsey.

func NotEqual

func NotEqual(t tester, expected, actual interface{})

NotEqual asserts that the given expected and actual arguments are not equal.

func NotOK

func NotOK(t tester, err error)

NotOK checks that an error was produced, and reacts accordingly.

func OK

func OK(t tester, err error)

OK checks that an error was not produced, and reacts accordingly.

func True

func True(t tester, condition bool, message string)

True asserts that the given condition is truthy.

Types

This section is empty.

Jump to

Keyboard shortcuts

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