testza

package module
v0.0.0-...-e4f8ef6 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: MIT Imports: 13 Imported by: 0

README

AtomicGo | testza

Latest Release Tests Coverage Unit test count Issues


Get The Module | Documentation | Contributing | Code of Conduct


AtomicGo

Description

Package testza contains util functions for writing tests in Go.

Install

# Execute this command inside your project
go get -u github.com/atomicgo/testza

or

// Add this to your imports
import "github.com/atomicgo/testza"

Documentation

Documentation with interactive examples on pkg.go.dev


AtomicGo.dev  ·  with ❤️ by @MarvinJWendt | MarvinJWendt.com

Documentation

Overview

Package testza contains util functions for writing tests in Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssertHelper

type AssertHelper struct {
}

AssertHelper contains assertion methods for the Go testing system.

func (AssertHelper) CompletesIn

func (a AssertHelper) CompletesIn(t testingT, duration time.Duration, f func(), msg ...interface{})

CompletesIn asserts that a function completes in a given time. Use this function to test that functions do not take too long to complete.

NOTE: Every system takes a different amount of time to complete a function. Do not set the duration too low, if you want consistent results.

func (AssertHelper) Contains

func (a AssertHelper) Contains(t testingT, object, element interface{}, msg ...interface{})

func (AssertHelper) Equal

func (a AssertHelper) Equal(t testingT, expected interface{}, actual interface{}, msg ...interface{})

Equal asserts that two objects are equal.

func (AssertHelper) EqualValues

func (a AssertHelper) EqualValues(t testingT, expected interface{}, actual interface{}, msg ...interface{})

EqualValues asserts that two objects have equal values.

func (AssertHelper) False

func (a AssertHelper) False(t testingT, value interface{}, msg ...interface{})

False asserts that an expression or object resolves to false.

func (AssertHelper) Implements

func (a AssertHelper) Implements(t testingT, interfaceObject, object interface{}, msg ...interface{})

Implements checks if an objects implements an interface.

testza.Use.Assert.Implements(t, (*YourInterface)(nil), new(YourObject))
testza.Use.Assert.Implements(t, (*fmt.Stringer)(nil), new(types.Const)) => pass

func (AssertHelper) KindOf

func (a AssertHelper) KindOf(t testingT, expectedKind reflect.Kind, object interface{}, msg ...interface{})

KindOf asserts that the object is a type of kind exptectedKind.

func (AssertHelper) Nil

func (a AssertHelper) Nil(t testingT, object interface{}, msg ...interface{})

Nil asserts that an object is nil.

func (AssertHelper) NoError

func (a AssertHelper) NoError(t testingT, err interface{}, msg ...interface{})

NoError asserts that an error is nil.

func (AssertHelper) NotCompletesIn

func (a AssertHelper) NotCompletesIn(t testingT, duration time.Duration, f func(), msg ...interface{})

NotCompletesIn asserts that a function does not complete in a given time. Use this function to test that functions do not complete to quickly. For example if your database connection completes in under a millisecond, there might be something wrong.

NOTE: Every system takes a different amount of time to complete a function. Do not set the duration too high, if you want consistent results.

func (AssertHelper) NotContains

func (a AssertHelper) NotContains(t testingT, object, element interface{}, msg ...interface{})

func (AssertHelper) NotEqual

func (a AssertHelper) NotEqual(t testingT, expected interface{}, actual interface{}, msg ...interface{})

NotEqual asserts that two objects are not equal.

func (AssertHelper) NotEqualValues

func (a AssertHelper) NotEqualValues(t testingT, expected interface{}, actual interface{}, msg ...interface{})

NotEqualValues asserts that two objects do not have equal values.

func (AssertHelper) NotImplements

func (a AssertHelper) NotImplements(t testingT, interfaceObject, object interface{}, msg ...interface{})

NotImplements checks if an object does not implement an interface.

testza.Use.Assert.NotImplements(t, (*YourInterface)(nil), new(YourObject))
testza.Use.Assert.NotImplements(t, (*fmt.Stringer)(nil), new(types.Const)) => fail, because types.Const does implement fmt.Stringer.

func (AssertHelper) NotKindOf

func (a AssertHelper) NotKindOf(t testingT, kind reflect.Kind, object interface{}, msg ...interface{})

NotKindOf asserts that the object is not a type of kind `kind`.

func (AssertHelper) NotNil

func (a AssertHelper) NotNil(t testingT, object interface{}, msg ...interface{})

NotNil assertsthat an object is not nil.

func (AssertHelper) NotNumeric

func (a AssertHelper) NotNumeric(t testingT, object interface{}, msg ...interface{})

Number checks if the object is not a numeric type. Numeric types are: Int, Int8, Int16, Int32, Int64, Float32, Float64, Uint, Uint8, Uint16, Uint32, Uint64, Complex64 and Complex128.

func (AssertHelper) NotPanic

func (a AssertHelper) NotPanic(t testingT, f func(), msg ...interface{})

NotPanic asserts that a function does not panic.

func (AssertHelper) NotZero

func (a AssertHelper) NotZero(t testingT, value interface{}, msg ...interface{})

NotZero asserts that the value is not the zero value for it's type.

assert.NotZero(t, 1337)
assert.NotZero(t, true)
assert.NotZero(t, "Hello, World")

func (AssertHelper) Numeric

func (a AssertHelper) Numeric(t testingT, object interface{}, msg ...interface{})

Numeric asserts that the object is a numeric type. Numeric types are: Int, Int8, Int16, Int32, Int64, Float32, Float64, Uint, Uint8, Uint16, Uint32, Uint64, Complex64 and Complex128.

func (AssertHelper) Panic

func (a AssertHelper) Panic(t testingT, f func(), msg ...interface{})

Panic asserts that a function panics.

func (AssertHelper) True

func (a AssertHelper) True(t testingT, value interface{}, msg ...interface{})

True asserts that an expression or object resolves to true.

func (AssertHelper) Zero

func (a AssertHelper) Zero(t testingT, value interface{}, msg ...interface{})

Zero asserts that the value is the zero value for it's type.

assert.Zero(t, 0)
assert.Zero(t, false)
assert.Zero(t, "")

type BoolsHelper

type BoolsHelper struct{}

func (BoolsHelper) Full

func (BoolsHelper) Full() []bool

Full returns true and false in a boolean slice.

type CaptureHelper

type CaptureHelper struct{}

CaptureHelper contains methods to capture terminal output.

func (*CaptureHelper) Stderr

func (h *CaptureHelper) Stderr(capture func(w io.Writer) error) (string, error)

CaptureStderr captures everything written to stderr from a specific function. You can use this method in tests, to validate that your functions writes a string to the terminal.

func (*CaptureHelper) Stdout

func (h *CaptureHelper) Stdout(capture func(w io.Writer) error) (string, error)

CaptureStdout captures everything written to stdout from a specific function. You can use this method in tests, to validate that your functions writes a string to the terminal.

type Floats64Helper

type Floats64Helper struct{}

Floats64Helper contains integer test sets.

func (Floats64Helper) Full

func (h Floats64Helper) Full() (floats []float64)

func (Floats64Helper) GenerateRandomNegative

func (h Floats64Helper) GenerateRandomNegative(count int, min float64) (floats []float64)

GenerateRandomNegative generates random negative integers with a minimum of min. If the minimum is positive, it will be converted to a negative number. If it is set to 0, there is no limit.

func (Floats64Helper) GenerateRandomPositive

func (h Floats64Helper) GenerateRandomPositive(count int, max float64) (floats []float64)

GenerateRandomPositive generates random positive integers with a maximum of max. If the maximum is 0, or below, the maximum will be set to math.MaxInt64.

func (Floats64Helper) GenerateRandomRange

func (h Floats64Helper) GenerateRandomRange(count int, min, max float64) (floats []float64)

GenerateRandomRange generates random positive integers with a maximum of max. If the maximum is 0, or below, the maximum will be set to math.MaxInt64.

func (Floats64Helper) Modify

func (h Floats64Helper) Modify(inputSlice []float64, f func(index int, value float64) float64) (floats []float64)

Modify returns a modified version of a test set.

type Helper

type Helper struct {
	Assert  AssertHelper
	Mock    MockHelper
	Capture CaptureHelper
}

Helper contains helper methods for the Go testing system. Methods in here integrate directly with the default Go testing system, and give detailed output. The methods will trigger the test to fail, if your expected behavior didn't occur.

var Use Helper

Use util functions of testza directly in the default testing system of Go. Methods in here integrate directly with the default Go testing system, and give detailed output. The methods will trigger the test to fail, if your expected behavior didn't occur. If you want to get the results of those functions, you can use the methods in Getter via testza.Get.

type IntsHelper

type IntsHelper struct{}

IntsHelper contains integer test sets.

func (IntsHelper) Full

func (h IntsHelper) Full() (ints []int)

func (IntsHelper) GenerateRandomNegative

func (h IntsHelper) GenerateRandomNegative(count, min int) (ints []int)

GenerateRandomNegative generates random negative integers with a minimum of min. If the minimum is 0, or above, the maximum will be set to math.MinInt64.

func (IntsHelper) GenerateRandomPositive

func (h IntsHelper) GenerateRandomPositive(count, max int) (ints []int)

GenerateRandomPositive generates random positive integers with a maximum of max. If the maximum is 0, or below, the maximum will be set to math.MaxInt64.

func (IntsHelper) Modify

func (h IntsHelper) Modify(inputSlice []int, f func(index int, value int) int) (ints []int)

Modify returns a modified version of a test set.

type MockHelper

type MockHelper struct {
	Strings  StringsHelper
	Floats64 Floats64Helper
	Ints     IntsHelper
	Bools    BoolsHelper
}

MockHelper contains mocking methods for the Go testing system.

type StringsHelper

type StringsHelper struct{}

StringsHelper contains strings test sets.

func (StringsHelper) EmailAddresses

func (s StringsHelper) EmailAddresses() []string

EmailAddresses returns a test set with valid email addresses.

func (StringsHelper) Empty

func (s StringsHelper) Empty() []string

Empty returns a test set with a single empty string.

func (StringsHelper) Full

func (s StringsHelper) Full() (ret []string)

Full contains all string test sets plus ten generated random strings.

func (StringsHelper) GenerateRandom

func (s StringsHelper) GenerateRandom(count, length int) (result []string)

GenerateRandom returns random StringsHelper in a test set.

func (StringsHelper) HtmlTags

func (s StringsHelper) HtmlTags() []string

HtmlTags returns a test set with html tags.

func (StringsHelper) Limit

func (s StringsHelper) Limit(testSet []string, max int) []string

Limit limits a test set in size.

func (StringsHelper) Modify

func (s StringsHelper) Modify(inputSlice []string, f func(index int, value string) string) (ret []string)

Modify returns a modified version of a test set.

func (StringsHelper) Numeric

func (s StringsHelper) Numeric() []string

Numeric returns a test set with strings that are numeric. The highest number in here is "9223372036854775807", which is equal to the maxmim int64.

func (StringsHelper) RunTests

func (s StringsHelper) RunTests(t testingT, testSet []string, testFunc func(t *testing.T, index int, str string))

RunTests runs tests with a specific test set.

func (StringsHelper) Usernames

func (s StringsHelper) Usernames() []string

Usernames returns a test set with usernames.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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