Documentation
¶
Overview ¶
* Check and it's sub packages provide tool for writing property based tests
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Check ¶
Check checks if property holds. First parameter is *testing.T that will report error if property returns an error (property doesn't hold). The property paramter should be defined using property.Define. The config parameter, even though it is a variadice parameter it uses only the first instance of Config passed to it. If config is not specified default configuration is used (random seed and 100 iterations). Config will run property number of times equal to Iterations values, specified by config parameter or (100 if default value is used). Following example demonstrates how to use Check in tests:
package main_test import ( "fmt" "testing" "github.com/steffnova/go-check" "github.com/steffnova/go-check/generator" "github.com/steffnova/go-check/property" ) func TestSubtractionCommutativity(t *testing.T) { check.Check(t, property.Define( property.Inputs( generator.Int() generator.Int() ) property.Predicate(func(x, y int) error { if x-y != y-x { return fmt.Errorf("commutativity does not hold for subtraction.") } return nil }) )) }
Commutativity does not hold for subtraction operation for every x and y as it is defined in predicate. Because of this an error will be thrown that will report value for which property failed. If shrinking is possible, property.Define will report smallest possible value for which predicate didn't hold.
--- FAIL: TestSubtractionCommutativity (0.00s) Check failed after 1 tests with seed: 1646421732271105000. Property failed for inputs: [ <int> 0, <int> 1 ] Shrunk 123 time(s) Failure reason: commutativity does not hold for subtraction. Re-run: go test -run=TestSubtractionCommutativity -seed=1646421732271105000 -iterations=100
Types ¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
001-encode-decode
command
|
|
002-fizz-buzz
command
|
|
Package generator provides generators for all basic go types and can be used to generate random data for provided data type.
|
Package generator provides generators for all basic go types and can be used to generate random data for provided data type. |