Documentation ¶
Index ¶
- func RunM(m *testing.M) int
- type B
- func (ddb *B) Context() context.Context
- func (ddb *B) Elapsed() time.Duration
- func (ddb *B) Error(args ...any)
- func (ddb *B) Errorf(format string, args ...any)
- func (ddb *B) Fail()
- func (ddb *B) FailNow()
- func (ddb *B) Fatal(args ...any)
- func (ddb *B) Fatalf(format string, args ...any)
- func (ddb *B) ReportAllocs()
- func (ddb *B) ReportMetric(n float64, unit string)
- func (ddb *B) ResetTimer()
- func (ddb *B) Run(name string, f func(*testing.B)) bool
- func (ddb *B) RunParallel(body func(*testing.PB))
- func (ddb *B) SetBytes(n int64)
- func (ddb *B) SetParallelism(p int)
- func (ddb *B) Skip(args ...any)
- func (ddb *B) SkipNow()
- func (ddb *B) Skipf(format string, args ...any)
- func (ddb *B) StartTimer()
- func (ddb *B) StopTimer()
- type M
- type T
- func (ddt *T) Context() context.Context
- func (ddt *T) Deadline() (deadline time.Time, ok bool)
- func (ddt *T) Error(args ...any)
- func (ddt *T) Errorf(format string, args ...any)
- func (ddt *T) Fail()
- func (ddt *T) FailNow()
- func (ddt *T) Fatal(args ...any)
- func (ddt *T) Fatalf(format string, args ...any)
- func (ddt *T) Parallel()
- func (ddt *T) Run(name string, f func(*testing.T)) bool
- func (ddt *T) Setenv(key, value string)
- func (ddt *T) Skip(args ...any)
- func (ddt *T) SkipNow()
- func (ddt *T) Skipf(format string, args ...any)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type B ¶
B is a type alias for testing.B to provide additional methods for CI visibility.
func GetBenchmark ¶
GetBenchmark is a helper to return *gotesting.B from *testing.B. Internally, it is just a (*gotesting.B)(b) cast.
func (*B) Context ¶
Context returns the CI Visibility context of the Test span. This may be used to create test's children spans useful for integration tests.
func (*B) Elapsed ¶
Elapsed returns the measured elapsed time of the benchmark. The duration reported by Elapsed matches the one measured by StartTimer, StopTimer, and ResetTimer.
func (*B) Fail ¶
func (ddb *B) Fail()
Fail marks the function as having failed but continues execution.
func (*B) FailNow ¶
func (ddb *B) 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 (*B) ReportAllocs ¶
func (ddb *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) ReportMetric ¶
ReportMetric adds "n unit" to the reported benchmark results. If the metric is per-iteration, the caller should divide by b.N, and by convention units should end in "/op". ReportMetric overrides any previously reported value for the same unit. ReportMetric panics if unit is the empty string or if unit contains any whitespace. If unit is a unit normally reported by the benchmark framework itself (such as "allocs/op"), ReportMetric will override that metric. Setting "ns/op" to 0 will suppress that built-in metric.
func (*B) ResetTimer ¶
func (ddb *B) ResetTimer()
ResetTimer zeroes the elapsed benchmark time and memory allocation counters and deletes user-reported metrics. It does not affect whether the timer is running.
func (*B) Run ¶
Run benchmarks f as a subbenchmark with the given name. It reports whether there were any failures.
A subbenchmark is like any other benchmark. A benchmark that calls Run at least once will not be measured itself and will be called once with N=1.
func (*B) RunParallel ¶
RunParallel runs a benchmark in parallel. It creates multiple goroutines and distributes b.N iterations among them. The number of goroutines defaults to GOMAXPROCS. To increase parallelism for non-CPU-bound benchmarks, call SetParallelism before RunParallel. RunParallel is usually used with the go test -cpu flag.
The body function will be run in each goroutine. It should set up any goroutine-local state and then iterate until pb.Next returns false. It should not use the StartTimer, StopTimer, or ResetTimer functions, because they have global effect. It should also not call Run.
RunParallel reports ns/op values as wall time for the benchmark as a whole, not the sum of wall time or CPU time over each parallel goroutine.
func (*B) SetBytes ¶
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 (*B) SetParallelism ¶
SetParallelism sets the number of goroutines used by RunParallel to p*GOMAXPROCS. There is usually no need to call SetParallelism for CPU-bound benchmarks. If p is less than 1, this call will have no effect.
func (*B) SkipNow ¶
func (ddb *B) 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. 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 (*B) StartTimer ¶
func (ddb *B) StartTimer()
StartTimer starts timing a test. This function is called automatically before a benchmark starts, but it can also be used to resume timing after a call to StopTimer.
type T ¶
T is a type alias for testing.T to provide additional methods for CI visibility.
func GetTest ¶
GetTest is a helper to return *gotesting.T from *testing.T. Internally, it is just a (*gotesting.T)(t) cast.
func (*T) Context ¶
Context returns the CI Visibility context of the Test span. This may be used to create test's children spans useful for integration tests.
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 (ddt *T) Fail()
Fail marks the function as having failed but continues execution.
func (*T) FailNow ¶
func (ddt *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) Parallel ¶
func (ddt *T) Parallel()
Parallel signals that this test is to be run in parallel with (and only with) other parallel tests. When a test is run multiple times due to use of -test.count or -test.cpu, multiple instances of a single test never run in parallel with each other.
func (*T) Run ¶
Run runs f as a subtest of t called name. It runs f in a separate goroutine and blocks until f returns or calls t.Parallel to become a parallel test. Run reports whether f succeeded (or at least did not fail before calling t.Parallel).
Run may be called simultaneously from multiple goroutines, but all such calls must return before the outer test function for t returns.
func (*T) Setenv ¶
Setenv calls os.Setenv(key, value) and uses Cleanup to restore the environment variable to its original value after the test. Because Setenv affects the whole process, it cannot be used in parallel tests or tests with parallel ancestors.
func (*T) SkipNow ¶
func (ddt *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. 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.