Documentation
¶
Overview ¶
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
Note ¶
All functions in this package return a bool value indicating whether the assertion has passed.
Example Usage ¶
The following is a complete example using assert in a standard test function:
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSomething(t *testing.T) {
var a string = "Hello"
var b string = "Hello"
assert.Equal(t, a, b, "The two words should be the same.")
}
if you assert many times, use the format below:
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestSomething(t *testing.T) {
assert := assert.New(t)
var a string = "Hello"
var b string = "Hello"
assert.Equal(a, b, "The two words should be the same.")
}
Assertions ¶
Assertions allow you to easily write test code, and are global funcs in the assert package. All assertion functions take, as the first argument, the *testing.T object provided by the testing framework. This allows the assertion funcs to write the failings and other details to the correct place.
Every assertion function also takes an optional string message as the final argument, allowing custom error messages to be appended to the message the assertion method outputs.
Index ¶
- Variables
- func CallerInfo() []string
- func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool
- func Conditionf(t TestingT, comp Comparison, msg string, args ...interface{}) bool
- func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool
- func Containsf(t TestingT, s interface{}, contains interface{}, msg string, ...) bool
- func DirExists(t TestingT, path string, msgAndArgs ...interface{}) bool
- func DirExistsf(t TestingT, path string, msg string, args ...interface{}) bool
- func ElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface{}) (ok bool)
- func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, ...) bool
- func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func Emptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool
- func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) bool
- func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func Error(t TestingT, err error, msgAndArgs ...interface{}) bool
- func ErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool
- func ErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) bool
- func ErrorContains(t TestingT, theError error, contains string, msgAndArgs ...interface{}) bool
- func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) bool
- func ErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool
- func ErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool
- func Errorf(t TestingT, err error, msg string, args ...interface{}) bool
- func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, ...) bool
- func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time.Duration, ...) bool
- func EventuallyWithTf(t TestingT, condition func(collect *CollectT), waitFor time.Duration, ...) bool
- func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, ...) bool
- func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool
- func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool
- func FailNowf(t TestingT, failureMessage string, msg string, args ...interface{}) bool
- func Failf(t TestingT, failureMessage string, msg string, args ...interface{}) bool
- func False(t TestingT, value bool, msgAndArgs ...interface{}) bool
- func Falsef(t TestingT, value bool, msg string, args ...interface{}) bool
- func FileExists(t TestingT, path string, msgAndArgs ...interface{}) bool
- func FileExistsf(t TestingT, path string, msg string, args ...interface{}) bool
- func Greater(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func GreaterOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func Greaterf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) string
- func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, ...) bool
- func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, ...) bool
- func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, ...) bool
- func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, ...) bool
- func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, ...) bool
- func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, ...) bool
- func HTTPRedirect(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, ...) bool
- func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, ...) bool
- func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, ...) bool
- func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, ...) bool
- func HTTPSuccess(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, ...) bool
- func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, ...) bool
- func Implements(t TestingT, interfaceObject interface{}, object interface{}, ...) bool
- func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, ...) bool
- func InDelta(t TestingT, expected, actual interface{}, delta float64, ...) bool
- func InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, ...) bool
- func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, ...) bool
- func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, ...) bool
- func InDeltaSlicef(t TestingT, expected interface{}, actual interface{}, delta float64, ...) bool
- func InDeltaf(t TestingT, expected interface{}, actual interface{}, delta float64, ...) bool
- func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, ...) bool
- func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, ...) bool
- func InEpsilonSlicef(t TestingT, expected interface{}, actual interface{}, epsilon float64, ...) bool
- func InEpsilonf(t TestingT, expected interface{}, actual interface{}, epsilon float64, ...) bool
- func IsDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func IsDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func IsIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func IsIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func IsNonDecreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func IsNonDecreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func IsNonIncreasing(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func IsNonIncreasingf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func IsNotType(t TestingT, theType, object interface{}, msgAndArgs ...interface{}) bool
- func IsNotTypef(t TestingT, theType interface{}, object interface{}, msg string, ...) bool
- func IsType(t TestingT, expectedType, object interface{}, msgAndArgs ...interface{}) bool
- func IsTypef(t TestingT, expectedType interface{}, object interface{}, msg string, ...) bool
- func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool
- func JSONEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool
- func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) bool
- func Lenf(t TestingT, object interface{}, length int, msg string, args ...interface{}) bool
- func Less(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func LessOrEqual(t TestingT, e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func LessOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func Lessf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func Negative(t TestingT, e interface{}, msgAndArgs ...interface{}) bool
- func Negativef(t TestingT, e interface{}, msg string, args ...interface{}) bool
- func Never(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, ...) bool
- func Neverf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, ...) bool
- func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func Nilf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func NoDirExists(t TestingT, path string, msgAndArgs ...interface{}) bool
- func NoDirExistsf(t TestingT, path string, msg string, args ...interface{}) bool
- func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool
- func NoErrorf(t TestingT, err error, msg string, args ...interface{}) bool
- func NoFileExists(t TestingT, path string, msgAndArgs ...interface{}) bool
- func NoFileExistsf(t TestingT, path string, msg string, args ...interface{}) bool
- func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool
- func NotContainsf(t TestingT, s interface{}, contains interface{}, msg string, ...) bool
- func NotElementsMatch(t TestingT, listA, listB interface{}, msgAndArgs ...interface{}) (ok bool)
- func NotElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, ...) bool
- func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func NotEmptyf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func NotEqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func NotEqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func NotEqualf(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interface{}) bool
- func NotErrorAsf(t TestingT, err error, target interface{}, msg string, args ...interface{}) bool
- func NotErrorIs(t TestingT, err, target error, msgAndArgs ...interface{}) bool
- func NotErrorIsf(t TestingT, err error, target error, msg string, args ...interface{}) bool
- func NotImplements(t TestingT, interfaceObject interface{}, object interface{}, ...) bool
- func NotImplementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, ...) bool
- func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool
- func NotNilf(t TestingT, object interface{}, msg string, args ...interface{}) bool
- func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool
- func NotPanicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool
- func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool
- func NotRegexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool
- func NotSame(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func NotSamef(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func NotSubset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool)
- func NotSubsetf(t TestingT, list interface{}, subset interface{}, msg string, ...) bool
- func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool
- func NotZerof(t TestingT, i interface{}, msg string, args ...interface{}) bool
- func ObjectsAreEqual(expected, actual interface{}) bool
- func ObjectsAreEqualValues(expected, actual interface{}) bool
- func ObjectsExportedFieldsAreEqual(expected, actual interface{}) booldeprecated
- func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool
- func PanicsWithError(t TestingT, errString string, f PanicTestFunc, msgAndArgs ...interface{}) bool
- func PanicsWithErrorf(t TestingT, errString string, f PanicTestFunc, msg string, args ...interface{}) bool
- func PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool
- func PanicsWithValuef(t TestingT, expected interface{}, f PanicTestFunc, msg string, ...) bool
- func Panicsf(t TestingT, f PanicTestFunc, msg string, args ...interface{}) bool
- func Positive(t TestingT, e interface{}, msgAndArgs ...interface{}) bool
- func Positivef(t TestingT, e interface{}, msg string, args ...interface{}) bool
- func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool
- func Regexpf(t TestingT, rx interface{}, str interface{}, msg string, args ...interface{}) bool
- func Same(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool
- func Samef(t TestingT, expected interface{}, actual interface{}, msg string, ...) bool
- func Subset(t TestingT, list, subset interface{}, msgAndArgs ...interface{}) (ok bool)
- func Subsetf(t TestingT, list interface{}, subset interface{}, msg string, ...) bool
- func True(t TestingT, value bool, msgAndArgs ...interface{}) bool
- func Truef(t TestingT, value bool, msg string, args ...interface{}) bool
- func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, ...) bool
- func WithinDurationf(t TestingT, expected time.Time, actual time.Time, delta time.Duration, ...) bool
- func WithinRange(t TestingT, actual, start, end time.Time, msgAndArgs ...interface{}) bool
- func WithinRangef(t TestingT, actual time.Time, start time.Time, end time.Time, msg string, ...) bool
- func YAMLEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool
- func YAMLEqf(t TestingT, expected string, actual string, msg string, args ...interface{}) bool
- func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool
- func Zerof(t TestingT, i interface{}, msg string, args ...interface{}) bool
- type Assertions
- func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool
- func (a *Assertions) Conditionf(comp Comparison, msg string, args ...interface{}) bool
- func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Containsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) DirExists(path string, msgAndArgs ...interface{}) bool
- func (a *Assertions) DirExistsf(path string, msg string, args ...interface{}) bool
- func (a *Assertions) ElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) ElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Emptyf(object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool
- func (a *Assertions) EqualErrorf(theError error, errString string, msg string, args ...interface{}) bool
- func (a *Assertions) EqualExportedValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) EqualExportedValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) EqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Equalf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool
- func (a *Assertions) ErrorAs(err error, target interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) ErrorAsf(err error, target interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) ErrorContains(theError error, contains string, msgAndArgs ...interface{}) bool
- func (a *Assertions) ErrorContainsf(theError error, contains string, msg string, args ...interface{}) bool
- func (a *Assertions) ErrorIs(err error, target error, msgAndArgs ...interface{}) bool
- func (a *Assertions) ErrorIsf(err error, target error, msg string, args ...interface{}) bool
- func (a *Assertions) Errorf(err error, msg string, args ...interface{}) bool
- func (a *Assertions) Eventually(condition func() bool, waitFor time.Duration, tick time.Duration, ...) bool
- func (a *Assertions) EventuallyWithT(condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, ...) bool
- func (a *Assertions) EventuallyWithTf(condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, ...) bool
- func (a *Assertions) Eventuallyf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, ...) bool
- func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Exactlyf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool
- func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) bool
- func (a *Assertions) FailNowf(failureMessage string, msg string, args ...interface{}) bool
- func (a *Assertions) Failf(failureMessage string, msg string, args ...interface{}) bool
- func (a *Assertions) False(value bool, msgAndArgs ...interface{}) bool
- func (a *Assertions) Falsef(value bool, msg string, args ...interface{}) bool
- func (a *Assertions) FileExists(path string, msgAndArgs ...interface{}) bool
- func (a *Assertions) FileExistsf(path string, msg string, args ...interface{}) bool
- func (a *Assertions) Greater(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) GreaterOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) GreaterOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Greaterf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPBodyContainsf(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPBodyNotContainsf(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPErrorf(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPRedirectf(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPStatusCode(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPStatusCodef(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) HTTPSuccessf(handler http.HandlerFunc, method string, url string, values url.Values, ...) bool
- func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Implementsf(interfaceObject interface{}, object interface{}, msg string, ...) bool
- func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, ...) bool
- func (a *Assertions) InDeltaMapValues(expected interface{}, actual interface{}, delta float64, ...) bool
- func (a *Assertions) InDeltaMapValuesf(expected interface{}, actual interface{}, delta float64, msg string, ...) bool
- func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, ...) bool
- func (a *Assertions) InDeltaSlicef(expected interface{}, actual interface{}, delta float64, msg string, ...) bool
- func (a *Assertions) InDeltaf(expected interface{}, actual interface{}, delta float64, msg string, ...) bool
- func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, ...) bool
- func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, ...) bool
- func (a *Assertions) InEpsilonSlicef(expected interface{}, actual interface{}, epsilon float64, msg string, ...) bool
- func (a *Assertions) InEpsilonf(expected interface{}, actual interface{}, epsilon float64, msg string, ...) bool
- func (a *Assertions) IsDecreasing(object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) IsDecreasingf(object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) IsIncreasing(object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) IsIncreasingf(object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) IsNonDecreasing(object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) IsNonDecreasingf(object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) IsNonIncreasing(object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) IsNonIncreasingf(object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) IsNotType(theType interface{}, object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) IsNotTypef(theType interface{}, object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) IsTypef(expectedType interface{}, object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) bool
- func (a *Assertions) JSONEqf(expected string, actual string, msg string, args ...interface{}) bool
- func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) bool
- func (a *Assertions) Lenf(object interface{}, length int, msg string, args ...interface{}) bool
- func (a *Assertions) Less(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) LessOrEqual(e1 interface{}, e2 interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) LessOrEqualf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Lessf(e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Negative(e interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Negativef(e interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Never(condition func() bool, waitFor time.Duration, tick time.Duration, ...) bool
- func (a *Assertions) Neverf(condition func() bool, waitFor time.Duration, tick time.Duration, msg string, ...) bool
- func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Nilf(object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NoDirExists(path string, msgAndArgs ...interface{}) bool
- func (a *Assertions) NoDirExistsf(path string, msg string, args ...interface{}) bool
- func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) bool
- func (a *Assertions) NoErrorf(err error, msg string, args ...interface{}) bool
- func (a *Assertions) NoFileExists(path string, msgAndArgs ...interface{}) bool
- func (a *Assertions) NoFileExistsf(path string, msg string, args ...interface{}) bool
- func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotContainsf(s interface{}, contains interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotElementsMatch(listA interface{}, listB interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotElementsMatchf(listA interface{}, listB interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotEmptyf(object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotEqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotEqualValuesf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotEqualf(expected interface{}, actual interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotErrorAs(err error, target interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotErrorAsf(err error, target interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotErrorIs(err error, target error, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotErrorIsf(err error, target error, msg string, args ...interface{}) bool
- func (a *Assertions) NotImplements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotImplementsf(interfaceObject interface{}, object interface{}, msg string, ...) bool
- func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotNilf(object interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotPanics(f PanicTestFunc, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotPanicsf(f PanicTestFunc, msg string, args ...interface{}) bool
- func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotRegexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotSame(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotSamef(expected interface{}, actual interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotSubset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotSubsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) NotZerof(i interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Panics(f PanicTestFunc, msgAndArgs ...interface{}) bool
- func (a *Assertions) PanicsWithError(errString string, f PanicTestFunc, msgAndArgs ...interface{}) bool
- func (a *Assertions) PanicsWithErrorf(errString string, f PanicTestFunc, msg string, args ...interface{}) bool
- func (a *Assertions) PanicsWithValue(expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool
- func (a *Assertions) PanicsWithValuef(expected interface{}, f PanicTestFunc, msg string, args ...interface{}) bool
- func (a *Assertions) Panicsf(f PanicTestFunc, msg string, args ...interface{}) bool
- func (a *Assertions) Positive(e interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Positivef(e interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Regexpf(rx interface{}, str interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Same(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Samef(expected interface{}, actual interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) Subset(list interface{}, subset interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Subsetf(list interface{}, subset interface{}, msg string, args ...interface{}) bool
- func (a *Assertions) True(value bool, msgAndArgs ...interface{}) bool
- func (a *Assertions) Truef(value bool, msg string, args ...interface{}) bool
- func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, ...) bool
- func (a *Assertions) WithinDurationf(expected time.Time, actual time.Time, delta time.Duration, msg string, ...) bool
- func (a *Assertions) WithinRange(actual time.Time, start time.Time, end time.Time, msgAndArgs ...interface{}) bool
- func (a *Assertions) WithinRangef(actual time.Time, start time.Time, end time.Time, msg string, ...) bool
- func (a *Assertions) YAMLEq(expected string, actual string, msgAndArgs ...interface{}) bool
- func (a *Assertions) YAMLEqf(expected string, actual string, msg string, args ...interface{}) bool
- func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) bool
- func (a *Assertions) Zerof(i interface{}, msg string, args ...interface{}) bool
- type BoolAssertionFunc
- type CollectT
- type CompareTypedeprecated
- type Comparison
- type ComparisonAssertionFunc
- type ErrorAssertionFunc
- type PanicAssertionFunc
- type PanicTestFunc
- type TestingT
- type ValueAssertionFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var AnError = errors.New("assert.AnError general error for testing")
AnError is an error instance useful for testing. If the code does not care about error specifics, and only needs to return the error for example, this error should be used to make the test code more readable.
Functions ¶
func CallerInfo ¶
func CallerInfo() []string
CallerInfo returns an array of strings containing the file and line number of each stack frame leading from the current test to the assert call that failed.
func Condition ¶
func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool
Condition uses a Comparison to assert a complex condition.
func Conditionf ¶ added in v1.2.0
func Conditionf(t TestingT, comp Comparison, msg string, args ...interface{}) bool
Conditionf uses a Comparison to assert a complex condition.
func Contains ¶
Contains asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
assert.Contains(t, "Hello World", "World")
assert.Contains(t, ["Hello", "World"], "World")
assert.Contains(t, {"Hello": "World"}, "Hello")
func Containsf ¶ added in v1.2.0
func Containsf(t TestingT, s interface{}, contains interface{}, msg string, args ...interface{}) bool
Containsf asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
assert.Containsf(t, "Hello World", "World", "error message %s", "formatted")
assert.Containsf(t, ["Hello", "World"], "World", "error message %s", "formatted")
assert.Containsf(t, {"Hello": "World"}, "Hello", "error message %s", "formatted")
func DirExists ¶ added in v1.2.0
DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
func DirExistsf ¶ added in v1.2.0
DirExistsf checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.
func ElementsMatch ¶ added in v1.2.0
ElementsMatch asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.
assert.ElementsMatch(t, [1, 3, 2, 3], [1, 3, 3, 2])
func ElementsMatchf ¶ added in v1.2.0
func ElementsMatchf(t TestingT, listA interface{}, listB interface{}, msg string, args ...interface{}) bool
ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements. If there are duplicate elements, the number of appearances of each of them in both lists should match.
assert.ElementsMatchf(t, [1, 3, 2, 3], [1, 3, 3, 2], "error message %s", "formatted")
func Empty ¶
Empty asserts that the given value is "empty".
Zero values are "empty".
Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
Slices, maps and channels with zero length are "empty".
Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
assert.Empty(t, obj)
func Emptyf ¶ added in v1.2.0
Emptyf asserts that the given value is "empty".
Zero values are "empty".
Arrays are "empty" if every element is the zero value of the type (stricter than "empty").
Slices, maps and channels with zero length are "empty".
Pointer values are "empty" if the pointer is nil or if the pointed value is "empty".
assert.Emptyf(t, obj, "error message %s", "formatted")
func Equal ¶
Equal asserts that two objects are equal.
assert.Equal(t, 123, 123)
Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.
func EqualError ¶
EqualError asserts that a function returned a non-nil error (i.e. an error) and that it is equal to the provided error.
actualObj, err := SomeFunction() assert.EqualError(t, err, expectedErrorString)
func EqualErrorf ¶ added in v1.2.0
func EqualErrorf(t TestingT, theError error, errString string, msg string, args ...interface{}) bool
EqualErrorf asserts that a function returned a non-nil error (i.e. an error) and that it is equal to the provided error.
actualObj, err := SomeFunction() assert.EqualErrorf(t, err, expectedErrorString, "error message %s", "formatted")
func EqualExportedValues ¶ added in v1.8.3
EqualExportedValues asserts that the types of two objects are equal and their public fields are also equal. This is useful for comparing structs that have private fields that could potentially differ.
type S struct {
Exported int
notExported int
}
assert.EqualExportedValues(t, S{1, 2}, S{1, 3}) => true
assert.EqualExportedValues(t, S{1, 2}, S{2, 3}) => false
func EqualExportedValuesf ¶ added in v1.8.3
func EqualExportedValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool
EqualExportedValuesf asserts that the types of two objects are equal and their public fields are also equal. This is useful for comparing structs that have private fields that could potentially differ.
type S struct {
Exported int
notExported int
}
assert.EqualExportedValuesf(t, S{1, 2}, S{1, 3}, "error message %s", "formatted") => true
assert.EqualExportedValuesf(t, S{1, 2}, S{2, 3}, "error message %s", "formatted") => false
func EqualValues ¶
EqualValues asserts that two objects are equal or convertible to the larger type and equal.
assert.EqualValues(t, uint32(123), int32(123))
func EqualValuesf ¶ added in v1.2.0
func EqualValuesf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool
EqualValuesf asserts that two objects are equal or convertible to the larger type and equal.
assert.EqualValuesf(t, uint32(123), int32(123), "error message %s", "formatted")
func Equalf ¶ added in v1.2.0
func Equalf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool
Equalf asserts that two objects are equal.
assert.Equalf(t, 123, 123, "error message %s", "formatted")
Pointer variable equality is determined based on the equality of the referenced values (as opposed to the memory addresses). Function equality cannot be determined and will always fail.
func Error ¶
Error asserts that a function returned a non-nil error (ie. an error).
actualObj, err := SomeFunction() assert.Error(t, err)
func ErrorAs ¶ added in v1.7.0
ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. This is a wrapper for errors.As.
func ErrorAsf ¶ added in v1.7.0
ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value. This is a wrapper for errors.As.
func ErrorContains ¶ added in v1.7.1
ErrorContains asserts that a function returned a non-nil error (i.e. an error) and that the error contains the specified substring.
actualObj, err := SomeFunction() assert.ErrorContains(t, err, expectedErrorSubString)
func ErrorContainsf ¶ added in v1.7.1
func ErrorContainsf(t TestingT, theError error, contains string, msg string, args ...interface{}) bool
ErrorContainsf asserts that a function returned a non-nil error (i.e. an error) and that the error contains the specified substring.
actualObj, err := SomeFunction() assert.ErrorContainsf(t, err, expectedErrorSubString, "error message %s", "formatted")
func ErrorIs ¶ added in v1.7.0
ErrorIs asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.
func ErrorIsf ¶ added in v1.7.0
ErrorIsf asserts that at least one of the errors in err's chain matches target. This is a wrapper for errors.Is.
func Errorf ¶ added in v1.2.0
Errorf asserts that a function returned a non-nil error (ie. an error).
actualObj, err := SomeFunction() assert.Errorf(t, err, "error message %s", "formatted")
func Eventually ¶ added in v1.4.0
func Eventually(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool
Eventually asserts that given condition will be met in waitFor time, periodically checking target function each tick.
assert.Eventually(t, func() bool { return true; }, time.Second, 10*time.Millisecond)
func EventuallyWithT ¶ added in v1.8.3
func EventuallyWithT(t TestingT, condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msgAndArgs ...interface{}) bool
EventuallyWithT asserts that given condition will be met in waitFor time, periodically checking target function each tick. In contrast to Eventually, it supplies a CollectT to the condition function, so that the condition function can use the CollectT to call other assertions. The condition is considered "met" if no errors are raised in a tick. The supplied CollectT collects all errors from one tick (if there are any). If the condition is not met before waitFor, the collected errors of the last tick are copied to t.
externalValue := false
go func() {
time.Sleep(8*time.Second)
externalValue = true
}()
assert.EventuallyWithT(t, func(c *assert.CollectT) {
// add assertions as needed; any assertion failure will fail the current tick
assert.True(c, externalValue, "expected 'externalValue' to be true")
}, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
func EventuallyWithTf ¶ added in v1.8.3
func EventuallyWithTf(t TestingT, condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool
EventuallyWithTf asserts that given condition will be met in waitFor time, periodically checking target function each tick. In contrast to Eventually, it supplies a CollectT to the condition function, so that the condition function can use the CollectT to call other assertions. The condition is considered "met" if no errors are raised in a tick. The supplied CollectT collects all errors from one tick (if there are any). If the condition is not met before waitFor, the collected errors of the last tick are copied to t.
externalValue := false
go func() {
time.Sleep(8*time.Second)
externalValue = true
}()
assert.EventuallyWithTf(t, func(c *assert.CollectT) {
// add assertions as needed; any assertion failure will fail the current tick
assert.True(c, externalValue, "expected 'externalValue' to be true")
}, 10*time.Second, 1*time.Second, "error message %s", "formatted")
func Eventuallyf ¶ added in v1.4.0
func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool
Eventuallyf asserts that given condition will be met in waitFor time, periodically checking target function each tick.
assert.Eventuallyf(t, func() bool { return true; }, time.Second, 10*time.Millisecond, "error message %s", "formatted")
func Exactly ¶
Exactly asserts that two objects are equal in value and type.
assert.Exactly(t, int32(123), int64(123))
func Exactlyf ¶ added in v1.2.0
func Exactlyf(t TestingT, expected interface{}, actual interface{}, msg string, args ...interface{}) bool
Exactlyf asserts that two objects are equal in value and type.
assert.Exactlyf(t, int32(123), int64(123), "error message %s", "formatted")
func Falsef ¶ added in v1.2.0
Falsef asserts that the specified value is false.
assert.Falsef(t, myBool, "error message %s", "formatted")
func FileExists ¶ added in v1.2.0
FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
func FileExistsf ¶ added in v1.2.0
FileExistsf checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.
func Greater ¶ added in v1.4.0
Greater asserts that the first element is greater than the second
assert.Greater(t, 2, 1) assert.Greater(t, float64(2), float64(1)) assert.Greater(t, "b", "a")
func GreaterOrEqual ¶ added in v1.4.0
GreaterOrEqual asserts that the first element is greater than or equal to the second
assert.GreaterOrEqual(t, 2, 1) assert.GreaterOrEqual(t, 2, 2) assert.GreaterOrEqual(t, "b", "a") assert.GreaterOrEqual(t, "b", "b")
func GreaterOrEqualf ¶ added in v1.4.0
func GreaterOrEqualf(t TestingT, e1 interface{}, e2 interface{}, msg string, args ...interface{}) bool
GreaterOrEqualf asserts that the first element is greater than or equal to the second
assert.GreaterOrEqualf(t, 2, 1, "error message %s", "formatted") assert.GreaterOrEqualf(t, 2, 2, "error message %s", "formatted") assert.GreaterOrEqualf(t, "b", "a", "error message %s", "formatted") assert.GreaterOrEqualf(t, "b", "b", "error message %s", "formatted")
func Greaterf ¶ added in v1.4.0
Greaterf asserts that the first element is greater than the second
assert.Greaterf(t, 2, 1, "error message %s", "formatted") assert.Greaterf(t, float64(2), float64(1), "error message %s", "formatted") assert.Greaterf(t, "b", "a", "error message %s", "formatted")
func HTTPBody ¶
HTTPBody is a helper that returns HTTP body of the response. It returns empty string if building a new request fails.
func HTTPBodyContains ¶
func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool
HTTPBodyContains asserts that a specified handler returns a body that contains a string.
assert.HTTPBodyContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
Returns whether the assertion was successful (true) or not (false).
func HTTPBodyContainsf ¶ added in v1.2.0
func HTTPBodyContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool
HTTPBodyContainsf asserts that a specified handler returns a body that contains a string.
assert.HTTPBodyContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
Returns whether the assertion was successful (true) or not (false).
func HTTPBodyNotContains ¶
func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}, msgAndArgs ...interface{}) bool
HTTPBodyNotContains asserts that a specified handler returns a body that does not contain a string.
assert.HTTPBodyNotContains(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky")
Returns whether the assertion was successful (true) or not (false).
func HTTPBodyNotContainsf ¶ added in v1.2.0
func HTTPBodyNotContainsf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}, msg string, args ...interface{}) bool
HTTPBodyNotContainsf asserts that a specified handler returns a body that does not contain a string.
assert.HTTPBodyNotContainsf(t, myHandler, "GET", "www.google.com", nil, "I'm Feeling Lucky", "error message %s", "formatted")
Returns whether the assertion was successful (true) or not (false).
func HTTPError ¶
func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool
HTTPError asserts that a specified handler returns an error status code.
assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
Returns whether the assertion was successful (true) or not (false).
func HTTPErrorf ¶ added in v1.2.0
func HTTPErrorf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool
HTTPErrorf asserts that a specified handler returns an error status code.
assert.HTTPErrorf(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}}
Returns whether the assertion was successful (true) or not (false).
func HTTPRedirect ¶
func HTTPRedirect(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool
HTTPRedirect asserts that a specified handler returns a redirect status code.
assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
Returns whether the assertion was successful (true) or not (false).
func HTTPRedirectf ¶ added in v1.2.0
func HTTPRedirectf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool
HTTPRedirectf asserts that a specified handler returns a redirect status code.
assert.HTTPRedirectf(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}}
Returns whether the assertion was successful (true) or not (false).
func HTTPStatusCode ¶ added in v1.6.0
func HTTPStatusCode(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, statuscode int, msgAndArgs ...interface{}) bool
HTTPStatusCode asserts that a specified handler returns a specified status code.
assert.HTTPStatusCode(t, myHandler, "GET", "/notImplemented", nil, 501)
Returns whether the assertion was successful (true) or not (false).
func HTTPStatusCodef ¶ added in v1.6.0
func HTTPStatusCodef(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, statuscode int, msg string, args ...interface{}) bool
HTTPStatusCodef asserts that a specified handler returns a specified status code.
assert.HTTPStatusCodef(t, myHandler, "GET", "/notImplemented", nil, 501, "error message %s", "formatted")
Returns whether the assertion was successful (true) or not (false).
func HTTPSuccess ¶
func HTTPSuccess(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, msgAndArgs ...interface{}) bool
HTTPSuccess asserts that a specified handler returns a success status code.
assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil)
Returns whether the assertion was successful (true) or not (false).
func HTTPSuccessf ¶ added in v1.2.0
func HTTPSuccessf(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, msg string, args ...interface{}) bool
HTTPSuccessf asserts that a specified handler returns a success status code.
assert.HTTPSuccessf(t, myHandler, "POST", "http://www.google.com", nil, "error message %s", "formatted")
Returns whether the assertion was successful (true) or not (false).
func Implements ¶
func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool
Implements asserts that an object is implemented by the specified interface.
assert.Implements(t, (*MyInterface)(nil), new(MyObject))
func Implementsf ¶ added in v1.2.0
func Implementsf(t TestingT, interfaceObject interface{}, object interface{}, msg string, args ...interface{}) bool
Implementsf asserts that an object is implemented by the specified interface.
assert.Implementsf(t, (*MyInterface)(nil), new(MyObject), "error message %s", "formatted")
func InDelta ¶
func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool
InDelta asserts that the two numerals are within delta of each other.
assert.InDelta(t, math.Pi, 22/7.0, 0.01)
func InDeltaMapValues ¶ added in v1.2.0
func InDeltaMapValues(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool
InDeltaMapValues is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
func InDeltaMapValuesf ¶ added in v1.2.0
func InDeltaMapValuesf(t TestingT, expected interface{}, actual interface{}, delta float64, msg string, args ...interface{}) bool
InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps. Both maps must have exactly the same keys.
func InDeltaSlice ¶
func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool
InDeltaSlice is the same as InDelta, except it compares two slices.