-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stateful testing: Clarification around InititalStateGen and PostConditions #75
Comments
I think there is a slight misconception between The The Mixing these two together basically means that you are testing that the expected state is equal to the expected state ... which is kind of pointless. |
Thanks for the quick response! I can see how that would make sense for testing simple properties or simple aspects of the state, where I can build a simple model of it in Go, but suppose the system builds some more complex state, properties of which I'd like to check. It seems wrong to rebuild all that in the For instance this seemed relatively straightforward when I implemented it without the type Event struct {
Type uint8
Name uint8
}
func executeEvents(s *sys, events []Event) {
for _, ev := range events {
method := ev.Type % 2
switch method {
case 0:
s.New(ev.Name)
case 1:
return // no op
}
}
}
func postCondition(s *sys) bool {
for i := 0; i < s.height; i++ {
_, ok := s.heights[i]
if !ok {
return false
}
}
return true
}
func TestSys2(t *testing.T) {
f := func(events []Event) bool {
s := &sys{
height: 0,
heights: make(map[int]uint8),
}
executeEvents(s, events)
return postCondition(s)
}
properties := gopter.NewProperties(nil)
// generater for events. event is just two uint8s
eventGen := gopter.DeriveGen(
func(typ uint8, name uint8) Event {
return Event{typ, name}
},
func(o Event) (uint8, uint8) {
return o.Type, o.Name
},
gen.UInt8(),
gen.UInt8(),
)
eventGen = gen.SliceOf(eventGen)
properties.Property("map state is correct", prop.ForAll(f, eventGen))
properties.TestingRun(t)
} |
Ok it looks like I'm mixing concerns here. It seems like the goal of If there might be interest in this, I can try and summarize in a new issue and close this one, otherwise we can just close this one. Thanks! Oh, InitialStateGen - I would expect it to run once for each set of commands being executed but it seems to run much more than that? |
You are right, with a complex In short: If you find a good programming model for more complex scenarios I would be certainly interested in it. As for |
Hello - thanks for a great testing library!
I'm trying to use gopter to test a simple stateful object. The object is initialized with no existing state, and then methods are called. After each method is called, I'd like to execute a check on the internal state of the object. Note this means I don't want to maintain a separate State object, I'd basically like my SystemUnderTest to also act as the State object and I don't want to have to do any kind of updates in NextState. Ideally the Run method will be called, executing one of the object's methods, and then PostCondition will check some property of the object.
I believe I managed to get this working, but a few things that aren't clear:
I've included a minimum viable example below.
Thanks!
The text was updated successfully, but these errors were encountered: