Property Based Testing (PBT) also called "QuickCheck" was something
invented by the Haskell folks a while back, it has since moved into
the Erlang and Clojure worlds (and probably other places). The idea
is that instead of giving your test a specific example to test you
let the computer randomly generate a large number (usually 100) of
examples until it finds one that does not work. It will then shrink
that example to the simplest case that will still generate that
error.
So lets say that you want to test a function to reverse a list, you
might decide to express the property like this one:
prop_reverse() ->
?FORALL(List,
list(integer()),
begin
List =:= reverse(reverse(List))
end).
When you run this it will generate 100 lists of integers and ensure
that for all lists that reversing it twice will always return the
original list.
Or a more recent example that I did was that I wanted to ensure that
a specific function would always do the correct thing when looking
up an item in a dictionary where the item was not present, ended up
with this test, I generate a dictionary, and a key, ensure that the
key is not present, then query my function on the dictionary to
ensure that it returns the empty list
prop_make_id_watchers_null()
->
?FORALL({AttrWatchers0,
Module},
{dict(),
binary()},
?IMPLIES((not (
dict:is_key(Module,
AttrWatchers0))),
begin
State =
#state{id_attr_watchers=AttrWatchers0},
[] =:=
boss_news_controller:make_id_watchers(Module,State
)
end)).
This podcast will explain more
http://mostlyerlang.com/2014/01/20/288/
--Zach