Documentation

Overview

Package testing provides support for automated testing of Go packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestMain

func TestMain(m *M)

Types

type B

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.

TODO: Implement benchmarks. This struct allows test files containing benchmarks to compile and run, but will not run the benchmarks themselves.

func (*B) Error

func (c *B) Error(args ...interface{})

Error is equivalent to Log followed by Fail.

func (*B) Errorf

func (c *B) Errorf(format string, args ...interface{})

Errorf is equivalent to Logf followed by Fail.

func (*B) Fail

func (c *B) Fail()

Fail marks the function as having failed but continues execution.

func (*B) FailNow

func (c *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).

func (*B) Failed

func (c *B) Failed() bool

Failed reports whether the function has failed.

func (*B) Fatal

func (c *B) Fatal(args ...interface{})

Fatal is equivalent to Log followed by FailNow.

func (*B) Fatalf

func (c *B) Fatalf(format string, args ...interface{})

Fatalf is equivalent to Logf followed by FailNow.

func (*B) Helper

func (c *B) Helper()

Helper is not implemented, it is only provided for compatibility.

func (*B) Log

func (c *B) Log(args ...interface{})

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 (*B) Logf

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. 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 (*B) Name

func (c *B) Name() string

Name returns the name of the running test or benchmark.

func (*B) ResetTimer

func (b *B) ResetTimer()

func (*B) Run

func (b *B) Run(name string, f func(b *B)) bool

func (*B) SetBytes

func (b *B) SetBytes(n int64)

func (*B) Skip

func (c *B) Skip(args ...interface{})

Skip is equivalent to Log followed by SkipNow.

func (*B) SkipNow

func (c *B) SkipNow()

SkipNow marks the test as having been skipped and stops its execution by calling runtime.Goexit.

func (*B) Skipf

func (c *B) Skipf(format string, args ...interface{})

Skipf is equivalent to Logf followed by SkipNow.

func (*B) Skipped

func (c *B) Skipped() bool

Skipped reports whether the test was skipped.

type InternalBenchmark

type InternalBenchmark struct {
	Name string
	F    func(b *B)
}

type InternalExample

type InternalExample struct {
	Name      string
	F         func()
	Output    string
	Unordered bool
}

type InternalTest

type InternalTest struct {
	Name string
	F    func(*T)
}

InternalTest is a reference to a test that should be called during a test suite run.

type M

type M struct {
	// tests is a list of the test names to execute
	Tests []InternalTest
}

M is a test suite.

func MainStart

func MainStart(deps interface{}, tests []InternalTest, benchmarks []InternalBenchmark, examples []InternalExample) *M

func (*M) Run

func (m *M) Run() int

Run the test suite.

type T

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 output when done.

func (*T) Error

func (c *T) Error(args ...interface{})

Error is equivalent to Log followed by Fail.

func (*T) Errorf

func (c *T) Errorf(format string, args ...interface{})

Errorf is equivalent to Logf followed by Fail.

func (*T) Fail

func (c *T) Fail()

Fail marks the function as having failed but continues execution.

func (*T) FailNow

func (c *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).

func (*T) Failed

func (c *T) Failed() bool

Failed reports whether the function has failed.

func (*T) Fatal

func (c *T) Fatal(args ...interface{})

Fatal is equivalent to Log followed by FailNow.

func (*T) Fatalf

func (c *T) Fatalf(format string, args ...interface{})

Fatalf is equivalent to Logf followed by FailNow.

func (*T) Helper

func (c *T) Helper()

Helper is not implemented, it is only provided for compatibility.

func (*T) Log

func (c *T) Log(args ...interface{})

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

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. 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) Name

func (c *T) Name() string

Name returns the name of the running test or benchmark.

func (*T) Run

func (t *T) Run(name string, f func(t *T)) bool

Run runs a subtest of f t called name. It waits until the subtest is finished and returns whether the subtest succeeded.

func (*T) Skip

func (c *T) Skip(args ...interface{})

Skip is equivalent to Log followed by SkipNow.

func (*T) SkipNow

func (c *T) SkipNow()

SkipNow marks the test as having been skipped and stops its execution by calling runtime.Goexit.

func (*T) Skipf

func (c *T) Skipf(format string, args ...interface{})

Skipf is equivalent to Logf followed by SkipNow.

func (*T) Skipped

func (c *T) Skipped() bool

Skipped reports whether the test was skipped.

type TB

type TB interface {
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	Fail()
	FailNow()
	Failed() bool
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
	Log(args ...interface{})
	Logf(format string, args ...interface{})
	Name() string
	Skip(args ...interface{})
	SkipNow()
	Skipf(format string, args ...interface{})
	Skipped() bool
	Helper()
}

TB is the interface common to T and B.