Documentation
¶
Overview ¶
Package assert provides test assertion functions for verifying expected conditions in Go tests. It offers a cleaner alternative to manually writing if statements with t.Fatal or t.Error calls.
Use this package when writing unit tests that need to verify equality, check for errors, validate nil values, or confirm that code panics as expected. Assertions fail the test immediately by default, but can be configured to continue execution using the Continue option.
Index ¶
- func Contains(t Testing, value any, check any, options ...Option)
- func Equals(t Testing, first any, second any, options ...Option)
- func Error(t Testing, err error, options ...Option)
- func ErrorExact(t Testing, err error, msg string, options ...Option)
- func ErrorPart(t Testing, err error, part string, options ...Option)
- func False(t Testing, value bool, options ...Option)
- func FloatEquals[T ~float64 | ~float32](t Testing, first T, second T, epsilon T, options ...Option)
- func Nil(t Testing, value any, options ...Option)
- func NoError(t Testing, err error, options ...Option)
- func NotEquals(t Testing, first any, second any, options ...Option)
- func NotNil(t Testing, value any, options ...Option)
- func Panic(t Testing, panicFunc func(), options ...Option)
- func PanicExact(t Testing, panicFunc func(), msg string, options ...Option)
- func PanicPart(t Testing, panicFunc func(), part string, options ...Option)
- func True(t Testing, value bool, options ...Option)
- type Option
- type Testing
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Contains ¶
Contains checks if an interface contains the contents of another. If the value is a string, it checks for a substring.
func ErrorExact ¶
ErrorExact checks if an error occurred with an exact message.
func FloatEquals ¶
FloatEquals checks if two floating point values are equal within a given epsilon.
func PanicExact ¶
PanicExact checks if a function panics with an exact message.