Documentation
¶
Overview ¶
Package suite implements an xUnit-style test runner, aiming for an optimum balance between simplicity and utility. It is based on the following packages:
- github.com/stretchr/testify/suite(https://pkg.go.dev/github.com/stretchr/testify/suite)
- github.com/smartystreets/gunit(https://pkg.go.dev/github.com/smartystreets/gunit)
For those using GoLand by JetBrains, you may find the following "live template" helpful:
func Test$NAME$Suite(t *testing.T) {
suite.Run(&$NAME$Suite{T: t}, suite.Options.UnitTests())
}
type $NAME$Suite struct {
*testing.T
}
func (this *$NAME$Suite) Setup() {
}
func (this *$NAME$Suite) Test$END$() {
}
Happy testing!
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Run ¶
func Run(fixture interface{}, options ...Option)
Run accepts a fixture with Test* methods and optional setup/teardown methods and executes the suite. Fixtures must be struct types which embed a *testing.T. Assuming a fixture struct with test methods 'Test1' and 'Test2' execution would proceed as follows:
- fixture.SetupSuite()
- fixture.Setup()
- fixture.Test1()
- fixture.Teardown()
- fixture.Setup()
- fixture.Test2()
- fixture.Teardown()
- fixture.TeardownSuite()
The methods provided by Options may be supplied to this function to tweak the execution.
Types ¶
type Opt ¶
type Opt struct{}
var Options Opt
Options provides the sole entrypoint to the option functions provided by this package.
func (Opt) FreshFixture ¶
FreshFixture signals to Run that the new instances of the provided fixture are to be instantiated for each and every test case. The Setup and Teardown methods are also executed on the specifically instantiated fixtures. NOTE: the SetupSuite and TeardownSuite methods are always run on the provided fixture instance, regardless of this options having been provided.
func (Opt) IntegrationTests ¶ added in v0.1.0
IntegrationTests is a composite option that signals to Run that the test suite should be treated as an integration test suite, avoiding parallelism and utilizing shared fixtures to allow reuse of potentially expensive resources.
func (Opt) ParallelFixture ¶
ParallelFixture signals to Run that the provided fixture instance can be executed in parallel with other go test functions. This option assumes that `go test` was invoked with the -parallel flag.
func (Opt) ParallelTests ¶
ParallelTests signals to Run that the test methods on the provided fixture instance can be executed in parallel with each other. This option assumes that `go test` was invoked with the -parallel flag.
func (Opt) SharedFixture ¶
SharedFixture signals to Run that the provided fixture instance is to be used to run all test methods. This mode is not compatible with ParallelFixture or ParallelTests and disables them.