Documentation ¶
Overview ¶
Package testza is a full-featured testing framework for Go. It integrates with the default test runner, so you can use it with the standard `go test` tool. Testza contains easy to use methods, like assertions, output capturing, mocking, and much more.
Testza is structured a bit differently than you might be used to in Go, but we think that it makes writing tests as easy and efficient as possible. After all, writing tests should be very simple and should not require you to study a whole framework. That's why we made testza to integrate perfectly with your IDE. You don't even have to lookup the documentation, as testza is self-explanatory.
Just type `testza.Use.` and you will get a list of all modules of testza in your IDE.
Index ¶
- type AssertHelper
- func (a AssertHelper) CompletesIn(t testRunner, duration time.Duration, f func(), msg ...interface{})
- func (a AssertHelper) Contains(t testRunner, object, element interface{}, msg ...interface{})
- func (a AssertHelper) Equal(t testRunner, expected interface{}, actual interface{}, msg ...interface{})
- func (a AssertHelper) EqualValues(t testRunner, expected interface{}, actual interface{}, msg ...interface{})
- func (a AssertHelper) False(t testRunner, value interface{}, msg ...interface{})
- func (a AssertHelper) Greater(t testRunner, object1, object2 interface{}, msg ...interface{})
- func (a AssertHelper) Implements(t testRunner, interfaceObject, object interface{}, msg ...interface{})
- func (a AssertHelper) KindOf(t testRunner, expectedKind reflect.Kind, object interface{}, ...)
- func (a AssertHelper) Less(t testRunner, object1, object2 interface{}, msg ...interface{})
- func (a AssertHelper) Nil(t testRunner, object interface{}, msg ...interface{})
- func (a AssertHelper) NoError(t testRunner, err interface{}, msg ...interface{})
- func (a AssertHelper) NotCompletesIn(t testRunner, duration time.Duration, f func(), msg ...interface{})
- func (a AssertHelper) NotContains(t testRunner, object, element interface{}, msg ...interface{})
- func (a AssertHelper) NotEqual(t testRunner, expected interface{}, actual interface{}, msg ...interface{})
- func (a AssertHelper) NotEqualValues(t testRunner, expected interface{}, actual interface{}, msg ...interface{})
- func (a AssertHelper) NotImplements(t testRunner, interfaceObject, object interface{}, msg ...interface{})
- func (a AssertHelper) NotKindOf(t testRunner, kind reflect.Kind, object interface{}, msg ...interface{})
- func (a AssertHelper) NotNil(t testRunner, object interface{}, msg ...interface{})
- func (a AssertHelper) NotNumeric(t testRunner, object interface{}, msg ...interface{})
- func (a AssertHelper) NotPanic(t testRunner, f func(), msg ...interface{})
- func (a AssertHelper) NotZero(t testRunner, value interface{}, msg ...interface{})
- func (a AssertHelper) Numeric(t testRunner, object interface{}, msg ...interface{})
- func (a AssertHelper) Panic(t testRunner, f func(), msg ...interface{})
- func (a AssertHelper) True(t testRunner, value interface{}, msg ...interface{})
- func (a AssertHelper) Zero(t testRunner, value interface{}, msg ...interface{})
- type CaptureHelper
- type Helper
- type MockHelper
- type MockInputsBoolsHelper
- type MockInputsFloats64Helper
- func (h MockInputsFloats64Helper) Full() (floats []float64)
- func (h MockInputsFloats64Helper) GenerateRandomNegative(count int, min float64) (floats []float64)
- func (h MockInputsFloats64Helper) GenerateRandomPositive(count int, max float64) (floats []float64)
- func (h MockInputsFloats64Helper) GenerateRandomRange(count int, min, max float64) (floats []float64)
- func (h MockInputsFloats64Helper) Modify(inputSlice []float64, f func(index int, value float64) float64) (floats []float64)
- func (s MockInputsFloats64Helper) RunTests(t testRunner, testSet []float64, ...)
- type MockInputsHelper
- type MockInputsIntsHelper
- func (h MockInputsIntsHelper) Full() (ints []int)
- func (h MockInputsIntsHelper) GenerateRandomNegative(count, min int) (ints []int)
- func (h MockInputsIntsHelper) GenerateRandomPositive(count, max int) (ints []int)
- func (h MockInputsIntsHelper) GenerateRandomRange(count, min, max int) (ints []int)
- func (h MockInputsIntsHelper) Modify(inputSlice []int, f func(index int, value int) int) (ints []int)
- func (s MockInputsIntsHelper) RunTests(t testRunner, testSet []int, testFunc func(t *testing.T, index int, i int))
- type MockInputsStringsHelper
- func (s MockInputsStringsHelper) EmailAddresses() []string
- func (s MockInputsStringsHelper) Empty() []string
- func (s MockInputsStringsHelper) Full() (ret []string)
- func (s MockInputsStringsHelper) GenerateRandom(count, length int) (result []string)
- func (s MockInputsStringsHelper) HtmlTags() []string
- func (s MockInputsStringsHelper) Limit(testSet []string, max int) []string
- func (s MockInputsStringsHelper) Modify(inputSlice []string, f func(index int, value string) string) (ret []string)
- func (s MockInputsStringsHelper) Numeric() []string
- func (s MockInputsStringsHelper) RunTests(t testRunner, testSet []string, ...)
- func (s MockInputsStringsHelper) Usernames() []string
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 testRunner, 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 testRunner, object, element interface{}, msg ...interface{})
func (AssertHelper) Equal ¶
func (a AssertHelper) Equal(t testRunner, expected interface{}, actual interface{}, msg ...interface{})
Equal asserts that two objects are equal.
func (AssertHelper) EqualValues ¶
func (a AssertHelper) EqualValues(t testRunner, expected interface{}, actual interface{}, msg ...interface{})
EqualValues asserts that two objects have equal values.
func (AssertHelper) False ¶
func (a AssertHelper) False(t testRunner, value interface{}, msg ...interface{})
False asserts that an expression or object resolves to false.
func (AssertHelper) Greater ¶
func (a AssertHelper) Greater(t testRunner, object1, object2 interface{}, msg ...interface{})
Greater asserts that the first object is greater than the second.
func (AssertHelper) Implements ¶
func (a AssertHelper) Implements(t testRunner, 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 testRunner, expectedKind reflect.Kind, object interface{}, msg ...interface{})
KindOf asserts that the object is a type of kind exptectedKind.
func (AssertHelper) Less ¶
func (a AssertHelper) Less(t testRunner, object1, object2 interface{}, msg ...interface{})
Less asserts that the first object is less than the second.
func (AssertHelper) Nil ¶
func (a AssertHelper) Nil(t testRunner, object interface{}, msg ...interface{})
Nil asserts that an object is nil.
func (AssertHelper) NoError ¶
func (a AssertHelper) NoError(t testRunner, err interface{}, msg ...interface{})
NoError asserts that an error is nil.
func (AssertHelper) NotCompletesIn ¶
func (a AssertHelper) NotCompletesIn(t testRunner, 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 testRunner, object, element interface{}, msg ...interface{})
func (AssertHelper) NotEqual ¶
func (a AssertHelper) NotEqual(t testRunner, expected interface{}, actual interface{}, msg ...interface{})
NotEqual asserts that two objects are not equal.
func (AssertHelper) NotEqualValues ¶
func (a AssertHelper) NotEqualValues(t testRunner, expected interface{}, actual interface{}, msg ...interface{})
NotEqualValues asserts that two objects do not have equal values.
func (AssertHelper) NotImplements ¶
func (a AssertHelper) NotImplements(t testRunner, 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 testRunner, 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 testRunner, object interface{}, msg ...interface{})
NotNil assertsthat an object is not nil.
func (AssertHelper) NotNumeric ¶
func (a AssertHelper) NotNumeric(t testRunner, 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 testRunner, f func(), msg ...interface{})
NotPanic asserts that a function does not panic.
func (AssertHelper) NotZero ¶
func (a AssertHelper) NotZero(t testRunner, value interface{}, msg ...interface{})
NotZero asserts that the value is not the zero value for it's type.
testza.Use.Assert.NotZero(t, 1337) testza.Use.Assert.NotZero(t, true) testza.Use.Assert.NotZero(t, "Hello, World")
func (AssertHelper) Numeric ¶
func (a AssertHelper) Numeric(t testRunner, 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 testRunner, f func(), msg ...interface{})
Panic asserts that a function panics.
func (AssertHelper) True ¶
func (a AssertHelper) True(t testRunner, value interface{}, msg ...interface{})
True asserts that an expression or object resolves to true.
func (AssertHelper) Zero ¶
func (a AssertHelper) Zero(t testRunner, value interface{}, msg ...interface{})
Zero asserts that the value is the zero value for it's type.
testza.Use.Assert.Zero(t, 0) testza.Use.Assert.Zero(t, false) testza.Use.Assert.Zero(t, "")
type CaptureHelper ¶
type CaptureHelper struct{}
CaptureHelper contains methods to capture terminal output.
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.
type MockHelper ¶
type MockHelper struct {
Inputs MockInputsHelper
}
MockHelper contains mocking methods for the Go testing system. Do not use this struct directly, use the methods in Use.
type MockInputsBoolsHelper ¶
type MockInputsBoolsHelper struct{}
func (MockInputsBoolsHelper) Full ¶
func (MockInputsBoolsHelper) Full() []bool
Full returns true and false in a boolean slice.
func (MockInputsBoolsHelper) Modify ¶
func (h MockInputsBoolsHelper) Modify(inputSlice []bool, f func(index int, value bool) bool) (floats []bool)
Modify returns a modified version of a test set.
func (MockInputsBoolsHelper) RunTests ¶
func (s MockInputsBoolsHelper) RunTests(t testRunner, testSet []bool, testFunc func(t *testing.T, index int, f bool))
RunTests runs a test for every value in a testset. You can use the value as input parameter for your functions, to sanity test against many different cases. This ensures that your functions have a correct error handling and enables you to test against hunderts of cases easily.
type MockInputsFloats64Helper ¶
type MockInputsFloats64Helper struct{}
MockInputsFloats64Helper contains integer test sets. Use testza.Use.Mock.Inputs.Floats64.
func (MockInputsFloats64Helper) Full ¶
func (h MockInputsFloats64Helper) Full() (floats []float64)
func (MockInputsFloats64Helper) GenerateRandomNegative ¶
func (h MockInputsFloats64Helper) 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 (MockInputsFloats64Helper) GenerateRandomPositive ¶
func (h MockInputsFloats64Helper) 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 (MockInputsFloats64Helper) GenerateRandomRange ¶
func (h MockInputsFloats64Helper) 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 (MockInputsFloats64Helper) Modify ¶
func (h MockInputsFloats64Helper) Modify(inputSlice []float64, f func(index int, value float64) float64) (floats []float64)
Modify returns a modified version of a test set.
func (MockInputsFloats64Helper) RunTests ¶
func (s MockInputsFloats64Helper) RunTests(t testRunner, testSet []float64, testFunc func(t *testing.T, index int, f float64))
RunTests runs a test for every value in a testset. You can use the value as input parameter for your functions, to sanity test against many different cases. This ensures that your functions have a correct error handling and enables you to test against hunderts of cases easily.
type MockInputsHelper ¶
type MockInputsHelper struct { Strings MockInputsStringsHelper Floats64 MockInputsFloats64Helper Ints MockInputsIntsHelper Bools MockInputsBoolsHelper }
type MockInputsIntsHelper ¶
type MockInputsIntsHelper struct{}
MockInputsIntsHelper contains integer test sets.
func (MockInputsIntsHelper) Full ¶
func (h MockInputsIntsHelper) Full() (ints []int)
Full returns a combination of every integer testset and some random integers (positive and negative).
func (MockInputsIntsHelper) GenerateRandomNegative ¶
func (h MockInputsIntsHelper) 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 (MockInputsIntsHelper) GenerateRandomPositive ¶
func (h MockInputsIntsHelper) 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 (MockInputsIntsHelper) GenerateRandomRange ¶
func (h MockInputsIntsHelper) GenerateRandomRange(count, min, max int) (ints []int)
GenerateRandomRange generates random integers with a range of min to max.
func (MockInputsIntsHelper) Modify ¶
func (h MockInputsIntsHelper) Modify(inputSlice []int, f func(index int, value int) int) (ints []int)
Modify returns a modified version of a test set.
func (MockInputsIntsHelper) RunTests ¶
func (s MockInputsIntsHelper) RunTests(t testRunner, testSet []int, testFunc func(t *testing.T, index int, i int))
RunTests runs a test for every value in a testset. You can use the value as input parameter for your functions, to sanity test against many different cases. This ensures that your functions have a correct error handling and enables you to test against hunderts of cases easily.
type MockInputsStringsHelper ¶
type MockInputsStringsHelper struct{}
MockInputsStringsHelper contains strings test sets.
func (MockInputsStringsHelper) EmailAddresses ¶
func (s MockInputsStringsHelper) EmailAddresses() []string
EmailAddresses returns a test set with valid email addresses.
func (MockInputsStringsHelper) Empty ¶
func (s MockInputsStringsHelper) Empty() []string
Empty returns a test set with a single empty string.
func (MockInputsStringsHelper) Full ¶
func (s MockInputsStringsHelper) Full() (ret []string)
Full contains all string test sets plus ten generated random strings.
func (MockInputsStringsHelper) GenerateRandom ¶
func (s MockInputsStringsHelper) GenerateRandom(count, length int) (result []string)
GenerateRandom returns random StringsHelper in a test set.
func (MockInputsStringsHelper) HtmlTags ¶
func (s MockInputsStringsHelper) HtmlTags() []string
HtmlTags returns a test set with html tags.
func (MockInputsStringsHelper) Limit ¶
func (s MockInputsStringsHelper) Limit(testSet []string, max int) []string
Limit limits a test set in size.
func (MockInputsStringsHelper) Modify ¶
func (s MockInputsStringsHelper) Modify(inputSlice []string, f func(index int, value string) string) (ret []string)
Modify returns a modified version of a test set.
func (MockInputsStringsHelper) Numeric ¶
func (s MockInputsStringsHelper) 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 (MockInputsStringsHelper) RunTests ¶
func (s MockInputsStringsHelper) RunTests(t testRunner, testSet []string, testFunc func(t *testing.T, index int, str string))
RunTests runs a test for every value in a testset. You can use the value as input parameter for your functions, to sanity test against many different cases. This ensures that your functions have a correct error handling and enables you to test against hunderts of cases easily.
func (MockInputsStringsHelper) Usernames ¶
func (s MockInputsStringsHelper) Usernames() []string
Usernames returns a test set with usernames.