quicktheories / QuickTheories

Property based testing for Java 8
Apache License 2.0
506 stars 51 forks source link

Additional feature? State-machine-based property testing #42

Open ccol002 opened 6 years ago

ccol002 commented 6 years ago

For a number of years, I have been on the lookout for a Java QuickCheck tool supporting state-machine-based properties.

For example http://www.quviq.com/products/erlang-quickcheck/ and http://proper.softlab.ntua.gr/Tutorials/PropEr_testing_of_finite_state_machines.html, and http://www.cs.waikato.ac.nz/~marku/mbt/modeljunit/ offer the possibility of specifying properties in terms of finite state machines. This is very convenient when the property being tested has elements of control-flow, e.g.: every time a newly registered user performs a call to "withdraw" before a call to "deposit" is marked as suspicious.

The idea is to have pre and post conditions on each machine transition such that the test is a traversal of the state machine which satisfies the preconditions, checking the satisfaction of the postconditions as the test progresses.

Are there any plans to support such functionality please?

hcoles commented 6 years ago

There is in fact some support for something similar already built in, although it is completely undocumented as it is somewhat experimental.

It's loosely based on scalacheck's stateful testing - so it is not tied to state machines, but it does let you compare the behaviour of your system to a model which could be a state machine.

The nearest thing to documentation is the example test.

https://github.com/ncredinburgh/QuickTheories/blob/master/core/src/test/java/com/example/StatefulTest.java

ccol002 commented 6 years ago

That's great to know! Hope there will be more of this in the future :)