package
1.10.0
Repository: https://github.com/stretchr/testify.git
Documentation: pkg.go.dev

# Packages

Package yaml is just an indirection to handle YAML deserialization.

# Functions

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.
Condition uses a Comparison to assert a complex condition.
Conditionf uses a Comparison to assert a complex condition.
Contains asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
Containsf asserts that the specified string, list(array, slice...) or map contains the specified substring or element.
DirExists checks whether a directory exists in the given path.
DirExistsf checks whether a directory exists in the given path.
ElementsMatch asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements.
ElementsMatchf asserts that the specified listA(array, slice...) is equal to specified listB(array, slice...) ignoring the order of the elements.
Empty asserts that the specified object is empty.
Emptyf asserts that the specified object is empty.
Equal asserts that two objects are equal.
EqualError asserts that a function returned an error (i.e.
EqualErrorf asserts that a function returned an error (i.e.
EqualExportedValues asserts that the types of two objects are equal and their public fields are also equal.
EqualExportedValuesf asserts that the types of two objects are equal and their public fields are also equal.
Equalf asserts that two objects are equal.
EqualValues asserts that two objects are equal or convertible to the larger type and equal.
EqualValuesf asserts that two objects are equal or convertible to the larger type and equal.
Error asserts that a function returned an error (i.e.
ErrorAs asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value.
ErrorAsf asserts that at least one of the errors in err's chain matches target, and if so, sets target to that error value.
ErrorContains asserts that a function returned an error (i.e.
ErrorContainsf asserts that a function returned an error (i.e.
Errorf asserts that a function returned an error (i.e.
ErrorIs asserts that at least one of the errors in err's chain matches target.
ErrorIsf asserts that at least one of the errors in err's chain matches target.
Eventually asserts that given condition will be met in waitFor time, periodically checking target function each tick.
Eventuallyf asserts that given condition will be met in waitFor time, periodically checking target function each tick.
EventuallyWithT asserts that given condition will be met in waitFor time, periodically checking target function each tick.
EventuallyWithTf asserts that given condition will be met in waitFor time, periodically checking target function each tick.
Exactly asserts that two objects are equal in value and type.
Exactlyf asserts that two objects are equal in value and type.
Fail reports a failure through.
Failf reports a failure through.
FailNow fails test.
FailNowf fails test.
False asserts that the specified value is false.
Falsef asserts that the specified value is false.
FileExists checks whether a file exists in the given path.
FileExistsf checks whether a file exists in the given path.
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").
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").
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").
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").
HTTPBody is a helper that returns HTTP body of the response.
HTTPBodyContains asserts that a specified handler returns a body that contains a string.
HTTPBodyContainsf asserts that a specified handler returns a body that contains a string.
HTTPBodyNotContains asserts that a specified handler returns a body that does not contain a string.
HTTPBodyNotContainsf asserts that a specified handler returns a body that does not contain a string.
HTTPError asserts that a specified handler returns an error status code.
HTTPErrorf asserts that a specified handler returns an error status code.
HTTPRedirect asserts that a specified handler returns a redirect status code.
HTTPRedirectf asserts that a specified handler returns a redirect status code.
HTTPStatusCode asserts that a specified handler returns a specified status code.
HTTPStatusCodef asserts that a specified handler returns a specified status code.
HTTPSuccess asserts that a specified handler returns a success status code.
HTTPSuccessf asserts that a specified handler returns a success status code.
Implements asserts that an object is implemented by the specified interface.
Implementsf asserts that an object is implemented by the specified interface.
InDelta asserts that the two numerals are within delta of each other.
InDeltaf asserts that the two numerals are within delta of each other.
InDeltaMapValues is the same as InDelta, but it compares all values between two maps.
InDeltaMapValuesf is the same as InDelta, but it compares all values between two maps.
InDeltaSlice is the same as InDelta, except it compares two slices.
InDeltaSlicef is the same as InDelta, except it compares two slices.
InEpsilon asserts that expected and actual have a relative error less than epsilon.
InEpsilonf asserts that expected and actual have a relative error less than epsilon.
InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices.
InEpsilonSlicef is the same as InEpsilon, except it compares each value from two slices.
IsDecreasing asserts that the collection is decreasing assert.IsDecreasing(t, []int{2, 1, 0}) assert.IsDecreasing(t, []float{2, 1}) assert.IsDecreasing(t, []string{"b", "a"}).
IsDecreasingf asserts that the collection is decreasing assert.IsDecreasingf(t, []int{2, 1, 0}, "error message %s", "formatted") assert.IsDecreasingf(t, []float{2, 1}, "error message %s", "formatted") assert.IsDecreasingf(t, []string{"b", "a"}, "error message %s", "formatted").
IsIncreasing asserts that the collection is increasing assert.IsIncreasing(t, []int{1, 2, 3}) assert.IsIncreasing(t, []float{1, 2}) assert.IsIncreasing(t, []string{"a", "b"}).
IsIncreasingf asserts that the collection is increasing assert.IsIncreasingf(t, []int{1, 2, 3}, "error message %s", "formatted") assert.IsIncreasingf(t, []float{1, 2}, "error message %s", "formatted") assert.IsIncreasingf(t, []string{"a", "b"}, "error message %s", "formatted").
IsNonDecreasing asserts that the collection is not decreasing assert.IsNonDecreasing(t, []int{1, 1, 2}) assert.IsNonDecreasing(t, []float{1, 2}) assert.IsNonDecreasing(t, []string{"a", "b"}).
IsNonDecreasingf asserts that the collection is not decreasing assert.IsNonDecreasingf(t, []int{1, 1, 2}, "error message %s", "formatted") assert.IsNonDecreasingf(t, []float{1, 2}, "error message %s", "formatted") assert.IsNonDecreasingf(t, []string{"a", "b"}, "error message %s", "formatted").
IsNonIncreasing asserts that the collection is not increasing assert.IsNonIncreasing(t, []int{2, 1, 1}) assert.IsNonIncreasing(t, []float{2, 1}) assert.IsNonIncreasing(t, []string{"b", "a"}).
IsNonIncreasingf asserts that the collection is not increasing assert.IsNonIncreasingf(t, []int{2, 1, 1}, "error message %s", "formatted") assert.IsNonIncreasingf(t, []float{2, 1}, "error message %s", "formatted") assert.IsNonIncreasingf(t, []string{"b", "a"}, "error message %s", "formatted").
IsType asserts that the specified objects are of the same type.
IsTypef asserts that the specified objects are of the same type.
JSONEq asserts that two JSON strings are equivalent.
JSONEqf asserts that two JSON strings are equivalent.
Len asserts that the specified object has specific length.
Lenf asserts that the specified object has specific length.
Less asserts that the first element is less than the second assert.Less(t, 1, 2) assert.Less(t, float64(1), float64(2)) assert.Less(t, "a", "b").
Lessf asserts that the first element is less than the second assert.Lessf(t, 1, 2, "error message %s", "formatted") assert.Lessf(t, float64(1), float64(2), "error message %s", "formatted") assert.Lessf(t, "a", "b", "error message %s", "formatted").
LessOrEqual asserts that the first element is less than or equal to the second assert.LessOrEqual(t, 1, 2) assert.LessOrEqual(t, 2, 2) assert.LessOrEqual(t, "a", "b") assert.LessOrEqual(t, "b", "b").
LessOrEqualf asserts that the first element is less than or equal to the second assert.LessOrEqualf(t, 1, 2, "error message %s", "formatted") assert.LessOrEqualf(t, 2, 2, "error message %s", "formatted") assert.LessOrEqualf(t, "a", "b", "error message %s", "formatted") assert.LessOrEqualf(t, "b", "b", "error message %s", "formatted").
Negative asserts that the specified element is negative assert.Negative(t, -1) assert.Negative(t, -1.23).
Negativef asserts that the specified element is negative assert.Negativef(t, -1, "error message %s", "formatted") assert.Negativef(t, -1.23, "error message %s", "formatted").
Never asserts that the given condition doesn't satisfy in waitFor time, periodically checking the target function each tick.
Neverf asserts that the given condition doesn't satisfy in waitFor time, periodically checking the target function each tick.
New makes a new Assertions object for the specified TestingT.
Nil asserts that the specified object is nil.
Nilf asserts that the specified object is nil.
NoDirExists checks whether a directory does not exist in the given path.
NoDirExistsf checks whether a directory does not exist in the given path.
NoError asserts that a function returned no error (i.e.
NoErrorf asserts that a function returned no error (i.e.
NoFileExists checks whether a file does not exist in a given path.
NoFileExistsf checks whether a file does not exist in a given path.
NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.
NotContainsf asserts that the specified string, list(array, slice...) or map does NOT contain the specified substring or element.
NotElementsMatch asserts that the specified listA(array, slice...) is NOT equal to specified listB(array, slice...) ignoring the order of the elements.
NotElementsMatchf asserts that the specified listA(array, slice...) is NOT equal to specified listB(array, slice...) ignoring the order of the elements.
NotEmpty asserts that the specified object is NOT empty.
NotEmptyf asserts that the specified object is NOT empty.
NotEqual asserts that the specified values are NOT equal.
NotEqualf asserts that the specified values are NOT equal.
NotEqualValues asserts that two objects are not equal even when converted to the same type assert.NotEqualValues(t, obj1, obj2).
NotEqualValuesf asserts that two objects are not equal even when converted to the same type assert.NotEqualValuesf(t, obj1, obj2, "error message %s", "formatted").
NotErrorAs asserts that none of the errors in err's chain matches target, but if so, sets target to that error value.
NotErrorAsf asserts that none of the errors in err's chain matches target, but if so, sets target to that error value.
NotErrorIs asserts that none of the errors in err's chain matches target.
NotErrorIsf asserts that none of the errors in err's chain matches target.
NotImplements asserts that an object does not implement the specified interface.
NotImplementsf asserts that an object does not implement the specified interface.
NotNil asserts that the specified object is not nil.
NotNilf asserts that the specified object is not nil.
NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic.
NotPanicsf asserts that the code inside the specified PanicTestFunc does NOT panic.
NotRegexp asserts that a specified regexp does not match a string.
NotRegexpf asserts that a specified regexp does not match a string.
NotSame asserts that two pointers do not reference the same object.
NotSamef asserts that two pointers do not reference the same object.
NotSubset asserts that the specified list(array, slice...) or map does NOT contain all elements given in the specified subset list(array, slice...) or map.
NotSubsetf asserts that the specified list(array, slice...) or map does NOT contain all elements given in the specified subset list(array, slice...) or map.
NotZero asserts that i is not the zero value for its type.
NotZerof asserts that i is not the zero value for its type.
ObjectsAreEqual determines if two objects are considered equal.
ObjectsAreEqualValues gets whether two objects are equal, or if their values are equal.
ObjectsExportedFieldsAreEqual determines if the exported (public) fields of two objects are considered equal.
Panics asserts that the code inside the specified PanicTestFunc panics.
Panicsf asserts that the code inside the specified PanicTestFunc panics.
PanicsWithError asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison.
PanicsWithErrorf asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value is an error that satisfies the EqualError comparison.
PanicsWithValue asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.
PanicsWithValuef asserts that the code inside the specified PanicTestFunc panics, and that the recovered panic value equals the expected panic value.
Positive asserts that the specified element is positive assert.Positive(t, 1) assert.Positive(t, 1.23).
Positivef asserts that the specified element is positive assert.Positivef(t, 1, "error message %s", "formatted") assert.Positivef(t, 1.23, "error message %s", "formatted").
Regexp asserts that a specified regexp matches a string.
Regexpf asserts that a specified regexp matches a string.
Same asserts that two pointers reference the same object.
Samef asserts that two pointers reference the same object.
Subset asserts that the specified list(array, slice...) or map contains all elements given in the specified subset list(array, slice...) or map.
Subsetf asserts that the specified list(array, slice...) or map contains all elements given in the specified subset list(array, slice...) or map.
True asserts that the specified value is true.
Truef asserts that the specified value is true.
WithinDuration asserts that the two times are within duration delta of each other.
WithinDurationf asserts that the two times are within duration delta of each other.
WithinRange asserts that a time is within a time range (inclusive).
WithinRangef asserts that a time is within a time range (inclusive).
YAMLEq asserts that two YAML strings are equivalent.
YAMLEqf asserts that two YAML strings are equivalent.
Zero asserts that i is the zero value for its type.
Zerof asserts that i is the zero value for its type.

# Variables

AnError is an error instance useful for testing.

# Structs

Assertions provides assertion methods around the TestingT interface.
CollectT implements the TestingT interface and collects all errors.

# Interfaces

TestingT is an interface wrapper around *testing.T.

# Type aliases

BoolAssertionFunc is a common function prototype when validating a bool value.
Deprecated: CompareType has only ever been for internal use and has accidentally been published since v1.6.0.
Comparison is a custom function that returns true on success and false on failure.
ComparisonAssertionFunc is a common function prototype when comparing two values.
ErrorAssertionFunc is a common function prototype when validating an error value.
PanicAssertionFunc is a common function prototype when validating a panic value.
PanicTestFunc defines a func that should be passed to the assert.Panics and assert.NotPanics methods, and represents a simple func that takes no arguments, and returns nothing.
ValueAssertionFunc is a common function prototype when validating a single value.