?
本文檔使用 php中文網(wǎng)手冊(cè) 發(fā)布
import "testing/quick"
概觀
指數(shù)
包快速實(shí)現(xiàn)實(shí)用功能,以幫助進(jìn)行黑匣子測(cè)試。
測(cè)試/快速軟件包已凍結(jié),不接受新功能。
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
func (s *CheckEqualError) Error() string
type CheckError
func (s *CheckError) Error() string
type Config
type Generator
type SetupError
func (s SetupError) Error() string
quick.go
func Check(f interface{}, config *Config) error
Check會(huì)查找f的輸入,任何返回bool的函數(shù)都會(huì)返回false。它重復(fù)調(diào)用f,每個(gè)參數(shù)都有任意值。如果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(f, g interface{}, config *Config) error
CheckEqual查找f和g返回不同結(jié)果的輸入。它用每個(gè)參數(shù)的任意值重復(fù)調(diào)用f和g。如果f和g返回不同的答案,則CheckEqual將返回描述輸入和輸出的* CheckEqualError。
func Value(t reflect.Type, rand *rand.Rand) (value reflect.Value, ok bool)
值返回給定類型的任意值。如果該類型實(shí)現(xiàn)了Generator接口,則將使用該接口。注意:要為結(jié)構(gòu)創(chuàng)建任意值,必須導(dǎo)出所有字段。
CheckEqualError是CheckEqual發(fā)現(xiàn)錯(cuò)誤的結(jié)果。
type CheckEqualError struct { CheckError Out1 []interface{} Out2 []interface{}}
func (s *CheckEqualError) Error() string
CheckError是檢查發(fā)現(xiàn)錯(cuò)誤的結(jié)果。
type CheckError struct { Count int In []interface{}}
func (s *CheckError) Error() string
配置結(jié)構(gòu)包含用于運(yùn)行測(cè)試的選項(xiàng)。
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)}
發(fā)生器可以生成它自己類型的隨機(jī)值。
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}
SetupError是使用檢查方式時(shí)出錯(cuò)的結(jié)果,與正在測(cè)試的函數(shù)無關(guān)。
type SetupError string
func (s SetupError) Error() string