Documentation ¶
Index ¶
- func Suite(t *testing.T, suite interface{}, opts ...Option)
- func SuiteP(t *testing.T, suite interface{}, opts ...Option)
- type Is
- func (is Is) Equal(value, expected interface{}, format string, i ...interface{})
- func (is Is) Err(err, target error, format string, args ...interface{})
- func (is Is) Fail(format string, args ...interface{})
- func (is Is) Log(msg string, i ...interface{})
- func (is Is) Panic(fn func(), format string, i ...interface{})
- func (is Is) Run(name string, testFn func(Is))
- func (is Is) RunP(name string, testFn func(Is))
- func (is Is) T() *testing.T
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Suite ¶
Suite runs the given test suite. All test functions must have the prefixed with Test and must take Is as the first and only argument and should not have a return value. Test functions are run sequentially in lexicographic order. To run tests in parallel use SuiteP.
// Example test func (s *SuiteName) TestName(Is){}
A test suite can define a Setup and Teardown function to setup the test suite and cleanup after the suite has completed. Both setup and teardown functions must have no arguments and return values. The Teardown function is always called after running all tests even if the tests fail.
func (s *suiteName) Setup(){ /* setup the set suite here */ } func (s *suiteName) Teardown(){ /* clean up after the test suite has completed. */ }
Types ¶
type Is ¶
Is is provides helpers for writing tests.
func (Is) Err ¶ added in v2.2.2
Err checks if any error in err's chain matches target. If no errors match target, the test fails.
func (Is) Fail ¶
Fail immediately fails the test. Calling this function is the equivalent of calling is.T().Fatalf.
func (Is) Log ¶
Log logs the given message. This is the equivalent of calling is.T().Log(msg). This function can be called from multiple goroutines concurrently.
func (Is) Panic ¶
Panic checks if calling the given function causes a panic. If the given function does not panic the test fails.
func (Is) Run ¶
Run runs the given sub test. This runs testFn in a separate goroutine and blocks until f returns or calls is.T().Parallel to become a parallel test.
type Option ¶ added in v2.4.0
type Option func(*options)
Option an options to be applied to the test.
func CmpAllUnexported ¶ added in v2.4.0
func CmpAllUnexported() Option
CmpAllUnexported enables comparing all unexported fields using Is.Equal. Using this options is not recommended since this will compare the unexported fields of structs from other packages. Use CmpUnexported instead.
func CmpOpt ¶ added in v2.4.0
CmpOpt adds the given [cmp.Option]s to the list of options passed to cmp.Diff.
func CmpUnexported ¶ added in v2.4.0
func CmpUnexported(types ...interface{}) Option
CmpUnexported allows comparing unexported fields of the given struct types.
func EquateEmpty ¶ added in v2.4.0
EquateEmpty sets if empty maps/slices and nil maps/slices are considered to be equal. Default: true
func EquateErrors ¶ added in v2.4.0
EquateErrors sets if the equality of errors is checked using errors.Is. Default: false