github.com/leanovate/gopter@v0.2.9/properties_test.go (about)

     1  package gopter_test
     2  
     3  import (
     4  	"os"
     5  	"testing"
     6  
     7  	"github.com/leanovate/gopter"
     8  	"github.com/leanovate/gopter/gen"
     9  	"github.com/leanovate/gopter/prop"
    10  )
    11  
    12  func TestProperties(t *testing.T) {
    13  	parameters := gopter.DefaultTestParameters()
    14  
    15  	properties := gopter.NewProperties(parameters)
    16  
    17  	properties.Property("always fail", prop.ForAll(
    18  		func(v int32) bool {
    19  			return false
    20  		},
    21  		gen.Int32(),
    22  	))
    23  
    24  	fakeT := &testing.T{}
    25  	properties.TestingRun(fakeT)
    26  	if !fakeT.Failed() {
    27  		t.Errorf("fakeT has not failed")
    28  	}
    29  }
    30  
    31  func TestPropertiesCustomReporter(t *testing.T) {
    32  	parameters := gopter.DefaultTestParameters()
    33  	properties := gopter.NewProperties(parameters)
    34  
    35  	properties.Property("always fail", prop.ForAll(
    36  		func(v int32) bool {
    37  			return false
    38  		},
    39  		gen.Int32(),
    40  	))
    41  
    42  	fakeT := &testing.T{}
    43  	properties.TestingRun(fakeT, gopter.NewFormatedReporter(true, 160, os.Stdout))
    44  	if !fakeT.Failed() {
    45  		t.Errorf("fakeT has not failed")
    46  	}
    47  }