Let them eat cakes.
If you don’t get it, you don’t need to read further.
Clojure repo with to play with property-base testing. The
brioches.core-test
shows a rather boring example with concat
.
The main point of this example is showing how you can completely
characterize the function with the basic algebraic properties.
One of these properties, namely assoc-closure?
, shows that
property-based testing can express and, more importantly, check
rather subtle aspects of functions under test: concat
returns a
lazy seq and, by doing so, does not respect the algebraic closure
property; on the other hand, we can relax the post-conditions by
requiring that concat
should return a Sequential
collection.
concat
is a very basic function but it shows how you can use
property-based testing as a proxy of the quality of your design,
something like traditional unit testing.
One of the most crucial aspects of property-based testing is the usage of generators. Here we show standard generators and generators built upon Prismatic’s Schema.
Just use
lein repl
and then issue
(reset)
to load the namespaces of the project.
- QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs
- test.check
- QuickCheck for Haskell
- QuickCheck for Erlang
- Prismatic Schema
- Herbert, a Clojure library defining a schema for edn values
- https://github.com/gfredericks/test.chuck
Copyright © 2014 Giorgio Valoti
Distributed under the Eclipse Public License, the same as Clojure.