Closed blt closed 5 years ago
Oh, I'm declaring my own generators because if I rely on the inferred generator the value of TestCities.Libraries
is always an empty map? I would expect this to fail, but it does not.
package main
import (
"github.com/leanovate/gopter"
"github.com/leanovate/gopter/arbitrary"
"testing"
)
type TestBook struct {
Title string
Content string
}
type TestLibrary struct {
Name string
Librarians uint8
Books []TestBook
}
type CityName = string
type TestCities struct {
Libraries map[CityName][]TestLibrary
}
func TestLibraries(t *testing.T) {
parameters := gopter.DefaultTestParameters()
parameters.MinSuccessfulTests = 1000000
arbitraries := arbitrary.DefaultArbitraries()
properties := gopter.NewProperties(parameters)
properties.Property("libraries always empty", arbitraries.ForAll(
func(tc *TestCities) bool {
return len(tc.Libraries) == 0
},
))
properties.TestingRun(t)
}
Just a short heads up since I was on vacation:
It is indeed true, that DefaultArbitraries do not include "map[something]anything", i.e. in the above example Libraries will be always empty, unless you register a generator for "map[CityName][]TestLibrary" I'll try to add this feature (though refection with map is pretty painful).
The long runtime actually seems not to be in "TestingRun" but rather somewhere in "genTestCities", i.e. while building the generator-tree ... this will require some research.
Added both of your examples to the tests (https://github.com/leanovate/gopter/blob/master/example_libraries_test.go). They should now only take a couple of milliseconds.
Otherwise just reopen the issue
Hi folks,
I've got a test whose runtime is real slow and I wonder if I'm doing something very wrong. Or, if I'm not doing something wrong if there are any options I've got to improve the test runtime. Here's a representative example of my actual tests:
My test builds a tree structure --
TestCities
->TestLibrary
->TestBook
-- and then runs a property to assert that no libraries are unsupervised. By construction this property will always pass:genTestLibrary
does not allow forTestLibrary.Libarians
to be 0. As expected, the property does pass but the runtime is around 30 seconds on my host. An example:Am I doing anything obviously wrong here?