Exploring QuickCheck by trying to implement a few QuickCheck examples using Rantly.
Some of the examples come from An introduction to QuickCheck with number theory and red black trees.
The red-black tree test is using the avl_tree gem, and 'state machine based' testing builds on finite_machine.
Note: Transition list for the state machine could be in theory generated using Rantly, which would automatically make it shrinkable. At the moment, its just random number - a probability weight used to determine which transition to perform. Also, one could do without a state machine, just calling the ops on the tree directly - otoh, state machine could provide a framework for multithreaded testing for free.
$ bundle
$ bundle exec rake test
- Jessica Kerr - Property based tests for better code. (Video) Prop testing pros & cons, composing generators, using ports&adapters to incorporate failure as a response from (remote) services, defining 'business value/success/correctness' in terms of properties.
- Property based testing, what is it (Article)
- Testing with generative testing: an example in Ruby (Article)
- Property based testing of higher order functions (Article)
- Introduction to QuickCheck (Video), talk by John Hughes, co-author of QuickCheck.
- Another talk on QuickCheck CI (Video) - Cherry-pick example-based failing tests from property based test runs.
- QuickCheck Package page (Docs)
- Original QuickCheck Sources (Sources)
- QuickCheck used to catch bugs in LevelDB (Slides)
- Corresponding Erlang properties/state machine (Sources)
- QuickCheck download from Quviq (Download)
For Ruby, there are different implementations:
For other languages Nat Pryce has compiled a list of quickcheck-like ports.
- There is a gem for random-data-generators called generatron. Especially the Generator module is an interesting read. Builds on Rantly.