Documentation
¶
Overview ¶
Package is is a mini testing helper.
func TestSomething(t *testing.T) {
is := is.New(t)
obj, err := MethodBeingTested()
is.OK(obj, err) // list of objects, all must be OK
is.Equal(obj, "Hello world")
}
OK ¶
is.OK asserts that the specified object is OK, which means different things for different types:
bool - OK means not false int - OK means not zero error - OK means nil string - OK means not "" func() - OK means does not panic everything else - OK means not nil
Equality ¶
is.Equal asserts that two objects are effectively equal.
Panics ¶
is.Panic and is.PanicWith asserts that the func() will panic. PanicWith specifies the panic text that is expected:
func TestInvalidArgs(t *testing.T) {
is := is.New(t)
is.Panic(func(){
SomeMethod(1)
})
is.PanicWith("invalid args, both cannot be nil", func(){
OtherMethod(nil, nil)
})
}
Relaxed ¶
To prevent is from stopping when the first assertion fails, you can use is.Relaxed(t), rather than is.New(t).
func TestManyThings(t *testing.T) {
is := is.Relaxed(t)
thing, err := Something();
is.OK(thing)
is.Nil(err)
another, err := Another();
is.Nil(another)
is.Err(err)
// all assertions will be tried
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type I ¶
type I interface {
// OK asserts that the specified objects are all OK.
OK(o ...interface{})
// Equal asserts that the two values are
// considered equal. Non strict.
Equal(a, b interface{})
// NotEqual asserts that the two values are not
// considered equal. Non strict.
NotEqual(a, b interface{})
// NoErr asserts that the value is not an
// error.
NoErr(err ...error)
// Err asserts that the value is an error.
Err(err ...error)
// Nil asserts that the specified objects are
// all nil.
Nil(obj ...interface{})
// NotNil asserts that the specified objects are
// all nil.
NotNil(obj ...interface{})
// True asserts that the specified objects are
// all true
True(obj ...interface{})
// False asserts that the specified objects are
// all true
False(obj ...interface{})
// Panic asserts that the specified function
// panics.
Panic(fn func())
// PanicWith asserts that the specified function
// panics with the specific message.
PanicWith(m string, fn func())
// Fail indicates that the test has failed with the
// specified formatted arguments.
Fail(args ...interface{})
// Failf indicates that the test has failed with the
// formatted arguments.
Failf(format string, args ...interface{})
}
I represents the is interface.
Click to show internal directories.
Click to hide internal directories.
