| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This package is not in the latest version of its module.
Go to latest Published: Sep 8, 2024 License: MITThe Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Modules with tagged versions give importers more predictable builds.
When a project reaches major version v1 it is considered stable.
Package assert 测试用的断言包
func TestAssert(t *testing.T) {
var v interface{} = 5
a := assert.New(t, false)
a.True(v==5, "v的值[%v]不等于5", v).
Equal(5, v, "v的值[%v]不等于5", v).
Nil(v).
TB().Log("success")
}
// 也可以对 testing.B 使用
func Benchmark1(b *testing.B) {
a := assert.New(b, false)
a.True(false)
for(i:=0; i<b.N; i++) {
// do something
}
}
This section is empty.
This section is empty.
DefaultFailureSprint 默认的 FailureSprintFunc 实现
func SetFailureSprintFunc(f FailureSprintFunc)
SetFailureSprintFunc 设置一个全局的转换方法
New 方法在默认情况下继承由此方法设置的值。
type Assertion struct {
// contains filtered or unexported fields
}
Assertion 是对 testing.TB 的二次包装
Assert 断言 expr 条件成立
f 表示在断言失败时输出的信息
普通用户直接使用 Assertion.True 效果是一样的,此函数主要供 Assertion 自身调用。
BetweenEqual 断言 v 是否存在于 [min,max] 之间
BetweenEqualMax 断言 v 是否存在于 (min,max] 之间
BetweenEqualMin 断言 v 是否存在于 [min,max) 之间
Contains 断言 container 包含 item 或是包含 item 中的所有项
若 container string、[]byte 和 []rune 类型, 都将会以字符串的形式判断其是否包含 item。 若 container 是个列表(array、slice、map)则判断其元素中是否包含 item 中的 的所有项,或是 item 本身就是 container 中的一个元素。
Error 断言有错误发生
传递未初始化的 error 值(var err error = nil),将断言失败
Assertion.NotNil 的特化版本,限定了类型为 error。
ErrorString 断言有错误发生且错误信息中包含指定的字符串 str
传递未初始化的 error 值(var err error = nil),将断言失败
NotContains 断言 container 不包含 item 或是不包含 item 中的所有项
PanicString 断言函数会发生 panic 且 panic 信息中包含指定的字符串内容
PanicValue 断言函数会抛出与 v 相同的信息
True 断言表达式 expr 为真
args 对应 fmt.Printf 函数中的参数,其中 args[0] 对应第一个参数 format,依次类推, 其它断言函数的 args 参数,功能与此相同。
WaitSeconds 等待 s 秒再执行后续操作
When 断言 expr 为 true 且在条件成立时调用 f
当有一组依赖 expr 的断言时,可以调用此方法。f 的参数 a 即为当前实例。
type Failure struct {
Action string // 操作名称,比如 Equal,NotEqual 等方法名称。
Values map[string]interface{} // 断言出错时返回的一些额外参数
// contains filtered or unexported fields
}
Failure 在断言出错时输出的错误信息
NewFailure 声明 Failure 对象
user 表示用户提交的反馈,其第一个元素如果是 string,那么将调用 fmt.Sprintf(user[0], user[1:]...) 对数据进行格式化,否则采用 fmt.Sprint(user...) 格式化数据; kv 表示当前错误返回的数据;
FailureSprintFunc 将 Failure 转换成文本的函数
NOTE: 可以使用此方法实现对错误信息的本地化。
func GetFailureSprintFunc() FailureSprintFunc
GetFailureSprintFunc 获取当前的 FailureSprintFunc 方法
| Back | FazBrowse Home | New Git URL |