testtable

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: MIT Imports: 1 Imported by: 0

README

Test Table

A library to help accelerate and maintain testing

Motivation

Table-driven tests are a well-defined pattern in Golang, but it often results in a lot of duplicated boiler plate code for defining the test definition and running the tests.

Goals

Ultimately, the hope for this library is that the programmer can just write the tests: "this is how I expect my function to behave given this input".

Design

testtable is a very small package intended to make it easier to quickly produce and write tests that can be easily refactored. It doesn't provide functionality - it's intended to be built upon by implementing the testtable.Run function.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenericTestDefinition

type GenericTestDefinition[InputType any, OutputType any] struct {
	Name           string
	Input          InputType
	FunctionToTest func(InputType) OutputType
	Expectations   func(OutputType)
}

GenericTestDefinition is a generic description of a simple "given this input then I expect this function to do X"

func (*GenericTestDefinition[I, O]) Run

func (test *GenericTestDefinition[I, O]) Run(parentTest *testing.T)

The general Run method runs the `FunctionToTest` with the `Input` and `Expectations` of the test definition

type Test

type Test interface {
	Run(*testing.T)
}

Test is the base type

type TestTable

type TestTable []Test

TestTable is a slice of `Test`s. This allows us to define many different types of tests and test definitions in one slice and run them all without needing to duplicate the looping logic

func (TestTable) Run

func (tests TestTable) Run(t *testing.T)

TestTable's Run method loops over all of and runs the tests in it

Jump to

Keyboard shortcuts

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