tabby

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2017 License: MIT Imports: 5 Imported by: 0

README

tabby

Table-driven tests for Go

Usage

some_package.go

func fib (n int) int {
  // some function here
}

some_package_test.go

func TestFib(t *testing.T) {
  tabby.Func(fib).
    Given(1).Expect(1).
    Given(2).Expect(1).
    Given(3).Expect(2).
    Given(4).Expect(3).
    Given(5).Expect(5).
    Given(6).Expect(8).
    Given(7).Expect(13).
    Run(t)
}

tabby also accepts variadic input and variadic output

func TestStringReplace(t *testing.T) {
  tabby.Func(StringReplace).
    Given("Hello World", "l", "++").Expect("He++++o Wor++d").
    Given("Hello World", "o", "++").Expect("Hell++ W++rld").
    Given("Hello World", " ", "++").Expect("Hello++World").
    Run(t)
}

Documentation

Overview

Package tabby is a framework for writing table-driven tests

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GivenEvent

type GivenEvent struct {
	// contains filtered or unexported fields
}

GivenEvent is the intermediate object returned by Given(), which must be followed immediately by Expect()

func (*GivenEvent) Expect

func (o *GivenEvent) Expect(outputs ...interface{}) *WrappedFunction

Expect sets the expected output values for the given values in the preceding Given() call

type WrappedFunction

type WrappedFunction struct {
	// contains filtered or unexported fields
}

WrappedFunction defines a test case for a given function

func Func

func Func(function interface{}) *WrappedFunction

Func wraps a function

func (*WrappedFunction) Given

func (w *WrappedFunction) Given(inputs ...interface{}) *GivenEvent

Given creates a scenario based on the inputs. This call should be immediately followed by an Expect() call.

func (*WrappedFunction) Run

func (w *WrappedFunction) Run(t *testing.T)

Run performs all scenarios as subtests

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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