suite

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2021 License: MIT Imports: 3 Imported by: 0

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:

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:

  1. fixture.SetupSuite()
  2. fixture.Setup()
  3. fixture.Test1()
  4. fixture.Teardown()
  5. fixture.Setup()
  6. fixture.Test2()
  7. fixture.Teardown()
  8. 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

func (Opt) FreshFixture() Option

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

func (Opt) IntegrationTests() Option

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

func (Opt) ParallelFixture() Option

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

func (Opt) ParallelTests() Option

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

func (Opt) SharedFixture() Option

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.

func (Opt) UnitTests added in v0.1.0

func (Opt) UnitTests() Option

UnitTests is a composite option that signals to Run that the test suite can be treated as a unit-test suite by employing parallelism and fresh fixtures to maximize the chances of exposing unwanted coupling between tests.

type Option added in v0.2.0

type Option func(*config)

Option is a function that modifies a config. See Options for provided behaviors.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL