单元测试类

package
v0.0.0-...-2910145 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gtest 提供了方便的测试工具集,用于进行单元测试。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(value, expect interface{})

Assert 检查 `value` 和 `expect` 是否相等。

func AssertEQ

func AssertEQ(value, expect interface{})

AssertEQ 检查 `value` 和 `expect` 是否相等,包括它们的 TYPE(类型)。

func AssertGE

func AssertGE(value, expect interface{})

AssertGE 检查 `value` 是否大于或等于 `expect`。 注意,只有字符串、整数和浮点类型可以使用 AssertGTE 进行比较,其他类型无效。

func AssertGT

func AssertGT(value, expect interface{})

AssertGT 检查 `value` 是否大于 `expect`。 注意,只有字符串、整数和浮点类型可以通过 AssertGT 进行比较, 其他类型是无效的。

func AssertIN

func AssertIN(value, expect interface{})

AssertIN 检查 `value` 是否在 `expect` 中。 `expect` 应该是一个切片类型, 但 `value` 可以是切片类型或基本类型变量。 TODO: 添加对 map 类型的支持。 TODO: gconv.Strings(0) 的结果不是 [0]

func AssertLE

func AssertLE(value, expect interface{})

AssertLE 检查 `value` 是否小于等于 `expect`。 注意,只有字符串、整数和浮点类型可以通过 AssertLTE 进行比较, 其他类型是无效的。

func AssertLT

func AssertLT(value, expect interface{})

AssertLT 检查 `value` 是否小于等于 `expect`。 注意,只有字符串、整数和浮点类型可以使用 AssertLT 进行比较, 其他类型无效。

func AssertNE

func AssertNE(value, expect interface{})

AssertNE 检查 `value` 和 `expect` 是否不相等。

func AssertNI

func AssertNI(value, expect interface{})

AssertNI 检查 `value` 是否不在 `expect` 中。 `expect` 应该是一个切片, 但 `value` 可以是切片或基本类型变量。 TODO: 添加对 map 的支持。

func AssertNQ

func AssertNQ(value, expect interface{})

AssertNQ 检查 `value` 和 `expect` 是否不相等,包括它们的类型。

func AssertNil

func AssertNil(value interface{})

AssertNil 断言 `value` 为 nil。

func C

func C(t *testing.T, f func(t *T))

C 创建一个单元测试用例。 参数 `t` 是指向标准库 testing.T 的指针(*testing.T)。 参数 `f` 是用于单元测试用例的闭包函数。

func DataContent

func DataContent(names ...string) string

DataContent 函数用于获取并返回当前包中指定testdata路径下的文件内容

func DataPath

func DataPath(names ...string) string

DataPath 获取并返回当前包的 testdata 路径, 该路径仅用于单元测试用例。 可选参数 `names` 指定子文件夹/子文件, 这些名称将与当前系统分隔符连接,并与路径一起返回。

func Error

func Error(message ...interface{})

Error 使用给定的`message`引发panic异常。

func Fatal

func Fatal(message ...interface{})

Fatal将`message`打印到标准错误输出(stderr)并退出进程。

Types

type T

type T struct {
	*testing.T
}

T 是测试用例管理对象。

func (*T) Assert

func (t *T) Assert(value, expect interface{})

Assert 检查 `value` 和 `expect` 是否相等。

func (*T) AssertEQ

func (t *T) AssertEQ(value, expect interface{})

AssertEQ 检查 `value` 和 `expect` 是否相等,包括它们的 TYPE(类型)。

func (*T) AssertGE

func (t *T) AssertGE(value, expect interface{})

AssertGE 检查 `value` 是否大于或等于 `expect`。 注意,只有字符串、整数和浮点类型可以使用 AssertGTE 进行比较,其他类型无效。

func (*T) AssertGT

func (t *T) AssertGT(value, expect interface{})

AssertGT 检查 `value` 是否大于 `expect`。 注意,只有字符串、整数和浮点类型可以通过 AssertGT 进行比较, 其他类型是无效的。

func (*T) AssertIN

func (t *T) AssertIN(value, expect interface{})

AssertIN 检查 `value` 是否在 `expect` 内。 其中 `expect` 应为一个切片, 但 `value` 可以是切片或基本类型变量。

func (*T) AssertLE

func (t *T) AssertLE(value, expect interface{})

AssertLE 检查 `value` 是否小于等于 `expect`。 注意,只有字符串、整数和浮点类型可以通过 AssertLTE 进行比较, 其他类型是无效的。

func (*T) AssertLT

func (t *T) AssertLT(value, expect interface{})

AssertLT 检查 `value` 是否小于等于 `expect`。 注意,只有字符串、整数和浮点类型可以使用 AssertLT 进行比较, 其他类型无效。

func (*T) AssertNE

func (t *T) AssertNE(value, expect interface{})

AssertNE 检查 `value` 和 `expect` 是否不相等。

func (*T) AssertNI

func (t *T) AssertNI(value, expect interface{})

AssertNI 检查 `value` 是否不在 `expect` 中。 `expect` 应该是一个切片, 但 `value` 可以是切片或基本类型变量。

func (*T) AssertNQ

func (t *T) AssertNQ(value, expect interface{})

AssertNQ 检查 `value` 和 `expect` 是否不相等,包括它们的类型。

func (*T) AssertNil

func (t *T) AssertNil(value interface{})

AssertNil 断言 `value` 为 nil。

func (*T) Error

func (t *T) Error(message ...interface{})

Error 使用给定的`message`引发panic异常。

func (*T) Fatal

func (t *T) Fatal(message ...interface{})

Fatal将`message`打印到标准错误输出(stderr)并退出进程。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL