Documentation
¶
Overview ¶
Package assert 提供最基础的测试断言函数,替代 testify/assert 的常用功能。
Index ¶
- func Contains(t testing.TB, s any, substr string, msgAndArgs ...any) bool
- func Empty(t testing.TB, value any, msgAndArgs ...any) bool
- func Equal(t testing.TB, expected, actual any, msgAndArgs ...any) bool
- func Error(t testing.TB, err error, msgAndArgs ...any) bool
- func ErrorIs(t testing.TB, err, target error, msgAndArgs ...any) bool
- func Eventually(t testing.TB, condition func() bool, waitFor, tick time.Duration, ...) bool
- func False(t testing.TB, value bool, msgAndArgs ...any) bool
- func Len(t testing.TB, value any, length int, msgAndArgs ...any) bool
- func Never(t testing.TB, condition func() bool, waitFor, tick time.Duration, ...) bool
- func Nil(t testing.TB, value any, msgAndArgs ...any) bool
- func NoError(t testing.TB, err error, msgAndArgs ...any) bool
- func NotEmpty(t testing.TB, value any, msgAndArgs ...any) bool
- func NotNil(t testing.TB, value any, msgAndArgs ...any) bool
- func True(t testing.TB, value bool, msgAndArgs ...any) bool
- func Zero(t testing.TB, value any, msgAndArgs ...any) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
Equal 断言两个值相等,不等时报告错误并标记测试失败。 msgAndArgs 支持可选的格式化消息,第一个参数是 format 字符串,后面是参数。 返回是否断言通过,便于用 if !assert.Equal(...) { return } 实现立即终止。
func Eventually ¶
func Eventually(t testing.TB, condition func() bool, waitFor, tick time.Duration, msgAndArgs ...any) bool
Eventually 断言 condition 在 waitFor 时间内最终返回 true,每隔 tick 轮询一次。 用于替代 sleep 等待异步结果,避免测试因固定等待时间而 flaky,返回是否断言通过。
func Never ¶
func Never(t testing.TB, condition func() bool, waitFor, tick time.Duration, msgAndArgs ...any) bool
Never 断言 condition 在 waitFor 时间内始终返回 false,每隔 tick 检查一次。 一旦条件成立立即报错,用于验证某事在观察窗口内绝不发生,返回是否断言通过。
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.