Package quick

import "testing/quick"
Overview
Index

Overview ▾

Package quick实现实用程序功能以帮助进行黑盒测试.

测试/快速软件包已冻结,并且不接受新功能.

func Check

func Check(f interface{}, config *Config) error

Check查找f的输入,f是返回布尔值的任何函数,例如f返回false. 它反复调用f,每个参数具有任意值. 如果f在给定输入上返回false,则Check以* CheckError形式返回该输入. 例如:

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

func CheckEqual(f, g interface{}, config *Config) error

CheckEqual查找f和g返回不同结果的输入. 它会重复调用f和g,并为每个参数使用任意值. 如果f和g返回不同的答案,则CheckEqual返回一个* CheckEqualError,描述输入和输出.

func Value

func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool)

值返回给定类型的任意值. 如果该类型实现了Generator接口,则将使用该接口. 注意:要为结构创建任意值,必须导出所有字段.

type CheckEqualError

CheckEqualError是CheckEqual发现错误的结果.

type CheckEqualError struct {
    CheckError
    Out1 []interface{}
    Out2 []interface{}
}

func (*CheckEqualError) Error

func (s *CheckEqualError) Error() string

type CheckError

CheckError是Check发现错误的结果.

type CheckError struct {
    Count int
    In    []interface{}
}

func (*CheckError) Error

func (s *CheckError) Error() string

type Config

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.
    // A count of zero implies the default, which is usually 100
    // but can be set by the -quickchecks flag.
    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)
}

type Generator

生成器可以生成其自己类型的随机值.

type Generator interface {
    // Generate returns a random instance of the type on which it is a
    // method using the size as a size hint.
    Generate(rand *rand.Rand, size int) reflect.Value
}

type SetupError

SetupError是使用检查方式时发生错误的结果,与所测试的功能无关.

type SetupError string

func (SetupError) Error

func (s SetupError) Error() string

by  ICOPY.SITE