Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

testing

v1.0.0
github.com/redforks/testing

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

3 matches

Top ↑

Package testing define helper / mock for unit testing

Because golang likes return error object instead of exception/panic, always handle error return values is a good practise. But sometimes it is impossible to got error, such as read from memory buffer, not handler them maybe maybe loose error because someday code changes, but handle them needs a lot of duplicate codes.

In package testing contains many test helper packages, suffix with `th', to handle these never happen errors. Test helper check the error result, if it is not nil, using testing.Fatal(err) to log the error object and abort current test case execution.

Functions

SetupTeardown

func SetupTeardown(setup, teardown func(), f func(t *testing.T)) func(t *testing.T)

SetupTeardown add setup/teardown support to nested testing.T.Run() sub tests.

Wrap sub test function, run setup before sub test, defer teardown after sub test.

Both setup and teardown can be nil.

TryWait

func TryWait(d time.Duration, try func() bool, timeout func())

TryWait the action until it returns true, call timeout if timeout.

Dependency graph