testing

package
v2.0.22 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Overview

F1's testing package is analagous to Go's built-in testing package. It provides a "t" type which ise injected into setup and iteration run functions, which also provides some common testing functionality such as the ability to perform assertions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResults added in v2.0.4

func CheckResults(t *T, done chan<- struct{})

Types

type RunFn

type RunFn func(t *T)

RunFn performs a single iteration of the scenario. 't' may be used for asserting results or failing the scenario.

type ScenarioFn

type ScenarioFn func(t *T) RunFn

ScenarioFn initialises a scenario and returns the iteration function (RunFn) to be invoked for every iteration of the tests.

type T

type T struct {
	// "iteration " + iteration number or "setup"
	Iteration string

	Scenario string
	// contains filtered or unexported fields
}

T is a type passed to Scenario functions to manage test state and support formatted test logs. A test ends when its Scenario function returns or calls any of the methods FailNow, Fatal, Fatalf. Those methods must be called only from the goroutine running the Scenario function. The other reporting methods, such as the variations of Log and Error, may be called simultaneously from multiple goroutines.

func NewT

func NewT(iter, scenarioName string) (*T, func())

func (*T) Cleanup

func (t *T) Cleanup(f func())

Cleanup registers a function to be called when the scenario or the iteration completes. Cleanup functions will be called in last added, first called order.

func (*T) Error

func (t *T) Error(err error)

Error is equivalent to Log followed by Fail.

func (*T) Errorf

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

Errorf is equivalent to Logf followed by Fail.

func (*T) Fail

func (t *T) Fail()

Fail marks the function as having failed but continues execution.

func (*T) FailNow

func (t *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 Scenario iteration. FailNow must be called from the goroutine running the Scenario, not from other goroutines created during the Scenario. Calling FailNow does not stop those other goroutines.

func (*T) Failed

func (t *T) Failed() bool

Failed reports whether the function has failed.

func (*T) Fatal

func (t *T) Fatal(err error)

Fatal is equivalent to Log followed by FailNow.

func (*T) Fatalf

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

Fatalf is equivalent to Logf followed by FailNow.

func (*T) Log

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

Log formats its arguments using default formatting, analogous to Println, and records the text in the error log. The text will be printed only if f1 is running in verbose mode.

func (*T) Logf

func (t *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. The text will be printed only if f1 is running in verbose mode.

func (*T) Logger

func (t *T) Logger() *log.Logger

func (*T) Name

func (t *T) Name() string

Name returns the name of the running Scenario.

func (*T) Require

func (t *T) Require() *require.Assertions

func (*T) TeardownFailed added in v2.0.9

func (t *T) TeardownFailed() bool

func (*T) Time

func (t *T) Time(stageName string, f func())

Time records a metric for the duration of the given function

Jump to

Keyboard shortcuts

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