tdtest

package
v0.10.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package tdtest provides support for table-driven testing.

Features include automatically updating of test values, automatic error message generation, and singling out single tests to run.

Auto updating fields is only supported for fields that are scalar types: string, bool, int*, and uint*. If the field is a string, the "actual" value may be any Go value that can meaningfully be printed with fmt.Sprint.

Index

Constants

This section is empty.

Variables

View Source
var UpdateTests = false

UpdateTests defines whether tests should be updated by default. This can be overridden on an individual basis using T.Update.

Functions

func Run

func Run[TC any](t *testing.T, table []TC, fn func(t *T, tc *TC))

Run runs the given function for each (selected) element in the table. TC must be a struct type. If that has a string field named "name", that value will be used to name the associated subtest.

Types

type T

type T struct {
	*testing.T
	// contains filtered or unexported fields
}

T is a single test case representing an element in a table. It embeds *testing.T, so all functions of testing.T are available.

func (*T) Equal

func (t *T) Equal(actual, field any, msgAndArgs ...any)

Equal compares two fields.

For auto updating to work, field must reference a field in the test case directly.

func (*T) Select

func (t *T) Select(tests ...any)

Select species which tests to run. The test may be an int, in which case it selects the table entry to run, or a string, which is matched against the last path of the test. An empty list runs all tests.

func (*T) Update

func (t *T) Update(enable bool)

Update specifies whether to update the Go structs in case of discrepancies. It overrides the default setting.

Jump to

Keyboard shortcuts

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