version: 1.10
package quick
import "testing/quick"
Overview
Package quick implements utility functions to help with black box testing.
The testing/quick package is frozen and is not accepting new features.
Index
- func Check(f interface{}, config *Config) error
- func CheckEqual(f, g interface{}, config *Config) error
- func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool)
- type CheckEqualError
- type CheckError
- type Config
- type Generator
- type SetupError
Package files
func Check
¶
Check looks for an input to f, any function that returns bool, such that f
returns false. It calls f repeatedly, with arbitrary values for each argument.
If f returns false on a given input, Check returns that input as a *CheckError.
For example:
func TestOddMultipleOfThree(t *testing.T) {
f := func(x int) bool {
y := OddMultipleOfThree(x)
return y%2 == 1 && y%3 == 0
}
if err := quick.Check(f, nil); err != nil {
t.Error(err)
}
}
func CheckEqual
¶
CheckEqual looks for an input on which f and g return different results. It
calls f and g repeatedly with arbitrary values for each argument. If f and g
return different answers, CheckEqual returns a *CheckEqualError describing the
input and the outputs.
func Value
¶
Value returns an arbitrary value of the given type. If the type implements the
Generator interface, that will be used. Note: To create arbitrary values for
structs, all the fields must be exported.
type CheckEqualError
¶
- type CheckEqualError struct {
- CheckError
- Out1 []interface{}
- Out2 []interface{}
- }
A CheckEqualError is the result CheckEqual finding an error.
func (*CheckEqualError) Error
¶
- func (s *CheckEqualError) Error() string
type CheckError
¶
- type CheckError struct {
- Count int
- In []interface{}
- }
A CheckError is the result of Check finding an error.
func (*CheckError) Error
¶
- func (s *CheckError) Error() string
type Config
¶
- type Config struct {
- // MaxCount sets the maximum number of iterations.
- // If zero, MaxCountScale is used.
- MaxCount int
- // MaxCountScale is a non-negative scale factor applied to the
- // default maximum.
- // If zero, the default is unchanged.
- MaxCountScale float64
- // Rand specifies a source of random numbers.
- // If nil, a default pseudo-random source will be used.
- Rand *rand.Rand
- // Values specifies a function to generate a slice of
- // arbitrary reflect.Values that are congruent with the
- // arguments to the function being tested.
- // If nil, the top-level Value function is used to generate them.
- Values func([]reflect.Value, *rand.Rand)
- }
A Config structure contains options for running a test.
type Generator
¶
A Generator can generate random values of its own type.
type SetupError
¶
- type SetupError string
A SetupError is the result of an error in the way that check is being used,
independent of the functions being tested.
func (SetupError) Error
¶
- func (s SetupError) Error() string