gtest

package
v2.9.3 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2025 License: MIT Imports: 9 Imported by: 4

Documentation

Overview

Package gtest provides convenient test utilities for unit testing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Assert

func Assert(value, expect any)

Assert checks `value` and `expect` EQUAL.

func AssertEQ

func AssertEQ(value, expect any)

AssertEQ checks `value` and `expect` EQUAL, including their TYPES.

func AssertGE

func AssertGE(value, expect any)

AssertGE checks `value` is GREATER OR EQUAL THAN `expect`. Notice that, only string, integer and float types can be compared by AssertGTE, others are invalid.

func AssertGT

func AssertGT(value, expect any)

AssertGT checks `value` is GREATER THAN `expect`. Notice that, only string, integer and float types can be compared by AssertGT, others are invalid.

func AssertIN

func AssertIN(value, expect any)

AssertIN checks `value` is IN `expect`. The `expect` should be a slice, but the `value` can be a slice or a basic type variable. TODO: gconv.Strings(0) is not [0]

func AssertLE

func AssertLE(value, expect any)

AssertLE checks `value` is LESS OR EQUAL THAN `expect`. Notice that, only string, integer and float types can be compared by AssertLTE, others are invalid.

func AssertLT

func AssertLT(value, expect any)

AssertLT checks `value` is LESS EQUAL THAN `expect`. Notice that, only string, integer and float types can be compared by AssertLT, others are invalid.

func AssertNE

func AssertNE(value, expect any)

AssertNE checks `value` and `expect` NOT EQUAL.

func AssertNI

func AssertNI(value, expect any)

AssertNI checks `value` is NOT IN `expect`. The `expect` should be a slice, but the `value` can be a slice or a basic type variable.

func AssertNQ

func AssertNQ(value, expect any)

AssertNQ checks `value` and `expect` NOT EQUAL, including their TYPES.

func AssertNil

func AssertNil(value any)

AssertNil asserts `value` is nil.

func C

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

C creates a unit testing case. The parameter `t` is the pointer to testing.T of stdlib (*testing.T). The parameter `f` is the closure function for unit testing case.

func DataContent added in v2.0.5

func DataContent(names ...string) string

DataContent retrieves and returns the file content for specified testdata path of current package

func DataPath added in v2.0.5

func DataPath(names ...string) string

DataPath retrieves and returns the testdata path of current package, which is used for unit testing cases only. The optional parameter `names` specifies the sub-folders/sub-files, which will be joined with current system separator and returned with the path.

func Error

func Error(message ...any)

Error panics with given `message`.

func Fatal

func Fatal(message ...any)

Fatal prints `message` to stderr and exit the process.

Types

type T

type T struct {
	*testing.T
}

T is the testing unit case management object.

func (*T) Assert

func (t *T) Assert(value, expect any)

Assert checks `value` and `expect` EQUAL.

func (*T) AssertEQ

func (t *T) AssertEQ(value, expect any)

AssertEQ checks `value` and `expect` EQUAL, including their TYPES.

func (*T) AssertGE

func (t *T) AssertGE(value, expect any)

AssertGE checks `value` is GREATER OR EQUAL THAN `expect`. Notice that, only string, integer and float types can be compared by AssertGTE, others are invalid.

func (*T) AssertGT

func (t *T) AssertGT(value, expect any)

AssertGT checks `value` is GREATER THAN `expect`. Notice that, only string, integer and float types can be compared by AssertGT, others are invalid.

func (*T) AssertIN

func (t *T) AssertIN(value, expect any)

AssertIN checks `value` is IN `expect`. The `expect` should be a slice, but the `value` can be a slice or a basic type variable.

func (*T) AssertLE

func (t *T) AssertLE(value, expect any)

AssertLE checks `value` is LESS OR EQUAL THAN `expect`. Notice that, only string, integer and float types can be compared by AssertLTE, others are invalid.

func (*T) AssertLT

func (t *T) AssertLT(value, expect any)

AssertLT checks `value` is LESS EQUAL THAN `expect`. Notice that, only string, integer and float types can be compared by AssertLT, others are invalid.

func (*T) AssertNE

func (t *T) AssertNE(value, expect any)

AssertNE checks `value` and `expect` NOT EQUAL.

func (*T) AssertNI

func (t *T) AssertNI(value, expect any)

AssertNI checks `value` is NOT IN `expect`. The `expect` should be a slice, but the `value` can be a slice or a basic type variable.

func (*T) AssertNQ

func (t *T) AssertNQ(value, expect any)

AssertNQ checks `value` and `expect` NOT EQUAL, including their TYPES.

func (*T) AssertNil

func (t *T) AssertNil(value any)

AssertNil asserts `value` is nil.

func (*T) Error

func (t *T) Error(message ...any)

Error panics with given `message`.

func (*T) Fatal

func (t *T) Fatal(message ...any)

Fatal prints `message` to stderr and exit the process.

Jump to

Keyboard shortcuts

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