func AllocsPerRun(runs int, f func()) (avg float64)
AllocsPerRun returns the average number of allocations during calls to f.
To compute the number of allocations, the function will first be run once as a warm-up. The average number of allocations over the specified number of runs will then be measured and returned.
AllocsPerRun sets GOMAXPROCS to 1 during its measurement and will restore it before returning.
func Main(matchString func(pat, str string) (bool, error), tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample)
An internal function but exported because it is cross-package; part of the implementation of the "go test" command.
func RunBenchmarks(matchString func(pat, str string) (bool, error), benchmarks []InternalBenchmark)
An internal function but exported because it is cross-package; part of the implementation of the "go test" command.
func RunExamples(matchString func(pat, str string) (bool, error), examples []InternalExample) (ok bool)
func RunTests(matchString func(pat, str string) (bool, error), tests []InternalTest) (ok bool)
func Short() bool
Short reports whether the -test.short flag is set.
func Verbose() bool
Verbose reports whether the -test.v flag is set.
type B struct {
N int
// contains filtered or unexported fields
}
B is a type passed to Benchmark functions to manage benchmark timing and to specify the number of iterations to run.
func (c *B) Error(args ...interface{})
Error is equivalent to Log followed by Fail.
func (c *B) Errorf(format string, args ...interface{})
Errorf is equivalent to Logf followed by Fail.
func (c *B) Fail()
Fail marks the function as having failed but continues execution.
func (c *B) FailNow()
FailNow marks the function as having failed and stops its execution. 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 (c *B) Failed() bool
Failed reports whether the function has failed.
func (c *B) Fatal(args ...interface{})
Fatal is equivalent to Log followed by FailNow.
func (c *B) Fatalf(format string, args ...interface{})
Fatalf is equivalent to Logf followed by FailNow.
func (c *B) Log(args ...interface{})
Log formats its arguments using default formatting, analogous to Println, and records the text in the error log. The text will be printed only if the test fails or the -test.v flag is set.
func (c *B) Logf(format string, args ...interface{})
Logf formats its arguments according to the format, analogous to Printf, and records the text in the error log. The text will be printed only if the test fails or the -test.v flag is set.
func (b *B) ReportAllocs()
ReportAllocs enables malloc statistics for this benchmark. It is equivalent to setting -test.benchmem, but it only affects the benchmark function that calls ReportAllocs.
func (b *B) ResetTimer()
ResetTimer sets the elapsed benchmark time to zero. It does not affect whether the timer is running.
func (b *B) SetBytes(n int64)
SetBytes records the number of bytes processed in a single operation. If this is called, the benchmark will report ns/op and MB/s.
func (c *B) Skip(args ...interface{})
Skip is equivalent to Log followed by SkipNow.
func (c *B) SkipNow()
SkipNow marks the test as having been skipped and stops its execution. 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 (c *B) Skipf(format string, args ...interface{})
Skipf is equivalent to Logf followed by SkipNow.
func (c *B) Skipped() bool
Skipped reports whether the test was skipped.
func (b *B) StartTimer()
StartTimer starts timing a test. This function is called automatically before a benchmark starts, but it can also used to resume timing after a call to StopTimer.
func (b *B) StopTimer()
StopTimer stops timing a test. This can be used to pause the timer while performing complex initialization that you don't want to measure.
type BenchmarkResult struct {
N int // The number of iterations.
T time.Duration // The total time taken.
Bytes int64 // Bytes processed in one iteration.
MemAllocs uint64 // The total number of memory allocations.
MemBytes uint64 // The total number of bytes allocated.
}
The results of a benchmark run.
func Benchmark(f func(b *B)) BenchmarkResult
Benchmark benchmarks a single function. Useful for creating custom benchmarks that do not use the "go test" command.
func (r BenchmarkResult) AllocedBytesPerOp() int64
func (r BenchmarkResult) AllocsPerOp() int64
func (r BenchmarkResult) MemString() string
func (r BenchmarkResult) NsPerOp() int64
func (r BenchmarkResult) String() string
type InternalBenchmark struct {
Name string
F func(b *B)
}
An internal type but exported because it is cross-package; part of the implementation of the "go test" command.
type InternalExample struct {
Name string
F func()
Output string
}
type InternalTest struct {
Name string
F func(*T)
}
An internal type but exported because it is cross-package; part of the implementation of the "go test" command.
type T struct {
// contains filtered or unexported fields
}
T is a type passed to Test functions to manage test state and support formatted test logs. Logs are accumulated during execution and dumped to standard error when done.
func (c *T) Error(args ...interface{})
Error is equivalent to Log followed by Fail.
func (c *T) Errorf(format string, args ...interface{})
Errorf is equivalent to Logf followed by Fail.
func (c *T) Fail()
Fail marks the function as having failed but continues execution.
func (c *T) FailNow()
FailNow marks the function as having failed and stops its execution. 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 (c *T) Failed() bool
Failed reports whether the function has failed.
func (c *T) Fatal(args ...interface{})
Fatal is equivalent to Log followed by FailNow.
func (c *T) Fatalf(format string, args ...interface{})
Fatalf is equivalent to Logf followed by FailNow.
func (c *T) Log(args ...interface{})
Log formats its arguments using default formatting, analogous to Println, and records the text in the error log. The text will be printed only if the test fails or the -test.v flag is set.
func (c *T) Logf(format string, args ...interface{})
Logf formats its arguments according to the format, analogous to Printf, and records the text in the error log. The text will be printed only if the test fails or the -test.v flag is set.
func (t *T) Parallel()
Parallel signals that this test is to be run in parallel with (and only with) other parallel tests.
func (c *T) Skip(args ...interface{})
Skip is equivalent to Log followed by SkipNow.
func (c *T) SkipNow()
SkipNow marks the test as having been skipped and stops its execution. 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 (c *T) Skipf(format string, args ...interface{})
Skipf is equivalent to Logf followed by SkipNow.
func (c *T) Skipped() bool
Skipped reports whether the test was skipped.
| Name | Synopsis | |
|---|---|---|
| .. | ||
| iotest | Package iotest implements Readers and Writers useful mainly for testing. | |
| quick | Package quick implements utility functions to help with black box testing. |