Documentation
¶
Index ¶
- type T
- func (p *T) Cleanup(f func())
- func (p *T) Deadline() (deadline time.Time, ok bool)
- func (p *T) Errorf(format string, args ...any)
- func (p *T) Errorln(args ...any)
- func (p *T) Fail()
- func (p *T) FailNow()
- func (p *T) Failed() bool
- func (p *T) Fatal(args ...any)
- func (p *T) Fatalf(format string, args ...any)
- func (p *T) Helper()
- func (p *T) Log(args ...any)
- func (p *T) Logf(format string, args ...any)
- func (p *T) Name() string
- func (p *T) Run(name string, f func()) bool
- func (p *T) Skip(args ...any)
- func (p *T) SkipNow()
- func (p *T) Skipf(format string, args ...any)
- func (p *T) Skipped() bool
- func (p *T) TempDir() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type T ¶
type T struct {
// contains filtered or unexported fields
}
func (*T) Cleanup ¶
func (p *T) Cleanup(f func())
Cleanup registers a function to be called when the test (or subtest) and all its subtests complete. Cleanup functions will be called in last added, first called order.
func (*T) Deadline ¶
Deadline reports the time at which the test binary will have exceeded the timeout specified by the -timeout flag.
The ok result is false if the -timeout flag indicates “no timeout” (0).
func (*T) Fail ¶
func (p *T) Fail()
Fail marks the function as having failed but continues execution.
func (*T) FailNow ¶
func (p *T) FailNow()
FailNow marks the function as having failed and stops its execution by calling runtime.Goexit (which then runs all deferred calls in the current goroutine). Execution will continue at the next test or benchmark. FailNow must be called from the goroutine running the test or benchmark function, not from other goroutines created during the test. Calling FailNow does not stop those other goroutines.
func (*T) Helper ¶
func (p *T) Helper()
Helper marks the calling function as a test helper function. When printing file and line information, that function will be skipped. Helper may be called simultaneously from multiple goroutines.
func (*T) Log ¶
Log formats its arguments using default formatting, analogous to Println, and records the text in the error log. For tests, the text will be printed only if the test fails or the -test.v flag is set. For benchmarks, the text is always printed to avoid having performance depend on the value of the -test.v flag.
func (*T) Logf ¶
Logf formats its arguments according to the format, analogous to Printf, and records the text in the error log. A final newline is added if not provided. For tests, the text will be printed only if the test fails or the -test.v flag is set. For benchmarks, the text is always printed to avoid having performance depend on the value of the -test.v flag.
func (*T) Run ¶
Run runs f as a subtest of t called name.
Run may be called simultaneously from multiple goroutines, but all such calls must return before the outer test function for t returns.
func (*T) SkipNow ¶
func (p *T) SkipNow()
SkipNow marks the test as having been skipped and stops its execution by calling runtime.Goexit. If a test fails (see Error, Errorf, Fail) and is then skipped, it is still considered to have failed. Execution will continue at the next test or benchmark. See also FailNow. SkipNow must be called from the goroutine running the test, not from other goroutines created during the test. Calling SkipNow does not stop those other goroutines.
func (*T) TempDir ¶
TempDir returns a temporary directory for the test to use. The directory is automatically removed by Cleanup when the test and all its subtests complete. Each subsequent call to t.TempDir returns a unique directory; if the directory creation fails, TempDir terminates the test by calling Fatal.