suite

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get[S Suite](tb testing.TB) (s S)

Get returns the instance of S which must have been previously registered using Register. If this is the first time Get is called for type S, the suite's Setup method will be ran. If the suite's Setup method failed, t.Fatal will be called.

func Register

func Register(s Suite)

Register allows a suite of type s to be later retrieved using Get. Only one instance of type s should be registered - multiple calls to Register using the same type will cause a panic.

func Run

func Run(m *testing.M) int

Run is a helper method which calls m.Run and the Teardown function, returning the exit code from m.Run, or 1 if an error occured during Teardown.

func Teardown

func Teardown() error

Teardown runs the Teardown method on registered suites who ran their Setup methods. If a suite was registered but never retrieved (by using the Get function), it's teardown method will not be run.

Types

type Base

type Base struct{}

Base is a placeholder type which can be embedded into other suites if they don't need to implement setup or teardown methods.

func (Base) Setup

func (Base) Setup(tb testing.TB) error

Setup is a no-op.

func (Base) Teardown

func (Base) Teardown() error

Teardown is a no-op.

type Suite

type Suite interface {
	Setup(t testing.TB) error
	Teardown() error
}

A Suite holds some shared state for multiple tests. The state should be instantiated during the Setup method and (if neccessary) cleaned up during the Teardown method.

Jump to

Keyboard shortcuts

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