Standard library / testing/quick

testing/quick.Check()

Generate inputs and search for a false property; nil means no counterexample was found within the configured trials. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
func Check(f any, config *Config) error

Parameters & Attributes

NameTypeDescription
fanyFunction under test or callback to run.
config*ConfigOptional property-test settings; nil uses defaults.

Return Value

error

Result of the operation described above.

Working Example

Example Snippetgo
package main
import (  "fmt"  "math/rand"  "testing/quick")
func main() {  err := quick.Check(func(x uint8) bool { return x^x == 0 }, &quick.Config{MaxCount: 20, Rand: rand.New(rand.NewSource(42))})  fmt.Println(err == nil)}
Go Reference