Documentation
¶
Index ¶
- func Contains[A any, B any](t TestingT, s A, contains B, msgAndArgs ...any) bool
- func ElementsMatch[T any](t TestingT, listA, listB T, msgAndArgs ...any) (ok bool)
- func Empty(t TestingT, object any, msgAndArgs ...any) bool
- func Equal[A any, B any](t TestingT, expected A, actual B, msgAndArgs ...any) bool
- func EqualError(t TestingT, theError error, errString string, msgAndArgs ...any) bool
- func EqualHTML(t TestingT, exptected, actual string)
- func Error(t TestingT, err error, msgAndArgs ...any) bool
- func False(t TestingT, value bool, msgAndArgs ...any) bool
- func Len(t TestingT, object any, length int, msgAndArgs ...any) bool
- func Nil(t TestingT, object any, msgAndArgs ...any) bool
- func NoError(t TestingT, err error, msgAndArgs ...any) bool
- func NotContains[A any, B any](t TestingT, s A, contains B, msgAndArgs ...any) bool
- func NotEqual[A any, B any](t TestingT, expected A, actual B, msgAndArgs ...any) bool
- func NotNil(t TestingT, object any, msgAndArgs ...any) bool
- func NotPanics(t TestingT, f testifyAssert.PanicTestFunc, msgAndArgs ...any) bool
- func NotSame[A any, B any](t TestingT, expected A, actual B, msgAndArgs ...any) bool
- func Panics(t TestingT, f testifyAssert.PanicTestFunc, msgAndArgs ...any) bool
- func Same[A any, B any](t TestingT, expected A, actual B, msgAndArgs ...any) bool
- func StrictEqual[A any, B any](t TestingT, expected A, actual B, msgAndArgs ...any) bool
- func True(t TestingT, value bool, msgAndArgs ...any) bool
- func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...any) bool
- type TestingT
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ElementsMatch ¶
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 Empty ¶
Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either a slice or a channel with len == 0.
assert.Empty(t, "")
func Equal ¶
Equal asserts two values are equal, this will ignore type. (int8, int32, int64, int, uint ...)
assert.Equal(t, 123, 123) // ok assert.Equal(t, uint32(123), int64(123)) // ok assert.Equal(t, 123, "123") // fail
This method only detects whether the values are equal (understand by your brain). If you want to strictly check the type, please use:
assert.StrictEqual(t, 123, int64(123))
func EqualError ¶
EqualError asserts that a function returned an error (i.e. not `nil`) and that it is equal to the provided error.
actualObj, err := SomeFunction() assert.EqualError(t, err, expectedErrorString)
func EqualHTML ¶
EqualHTML asserts two HTML equal, will ignore spaces / breaks between > <
assert.EqualHTML(t, "<p>Hello</p> <p>world<p>", "<p>Hello</p> <p>world<p>") // ok
func Error ¶
Error asserts that a function returned no error (i.e. `nil`).
actualObj, err := SomeFunction() if assert.Error(t, err) { assert.Equal(t, expectedObj, actualObj) }
func Len ¶
Len asserts that the specified object has specific length. Len also fails if the object has a type that len() not accept.
assert.Len(t, mySlice, 3)
func NoError ¶
NoError asserts that a function returned no error (i.e. `nil`).
actualObj, err := SomeFunction() if assert.NoError(t, err) { assert.Equal(t, expectedObj, actualObj) }
func NotContains ¶
NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.
assert.NotContains(t, "Hello World", "Earth") assert.NotContains(t, ["Hello", "World"], "Earth") assert.NotContains(t, {"Hello": "World"}, "Earth")
func NotEqual ¶
NotEqual asserts value not equal, ignore type.
assert.NotEqual(t, 12, 13) // ok assert.NotEqual(t, 12, int32(12)) // fail assert.NotEqual(t, 12, int32(13)) // ok
func NotPanics ¶
func NotPanics(t TestingT, f testifyAssert.PanicTestFunc, msgAndArgs ...any) bool
NotPanics asserts that the code inside the specified PanicTestFunc panics.
assert.NotPanics(t, func(){ GoCrazy() })
func NotSame ¶
NotSame asserts that two pointers do not reference the same object.
assert.NotSame(t, ptr1, ptr2)
Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.
func Panics ¶
func Panics(t TestingT, f testifyAssert.PanicTestFunc, msgAndArgs ...any) bool
Panics asserts that the code inside the specified PanicTestFunc panics.
assert.Panics(t, func(){ GoCrazy() })
func Same ¶
Same asserts that two pointers reference the same object.
assert.Same(t, ptr1, ptr2)
Both arguments must be pointer variables. Pointer variable sameness is determined based on the equality of both type and value.
func StrictEqual ¶
StrictEqual strictly asserts two values and type are equal.
assert.StrictEqual(t, 123, 123) assert.StrictEqual(t, 123, int64(123)) // fail