Gathering Statistics
While there’s nothing wrong with using in-shell samples to get a quick feel for how things work, a more pragmatic approach is to display values every time we run the tests, so that we can know at a glance whether anything looks odd or out of place. There are two functions that can be used for this: collect/2 and aggregate/2.
We’ll focus on collect/2 first, since it’s a bit more specific and straightforward, and then expand to aggregate/2.
Collecting
The collect(Value, PropertyResult) function allows you to gather the values of one specific metric per test and build stats out of all the runs that happened for a property. It’s special in that you need to use it to wrap the actual property result and add context to it:
About ... |
---|
Get Property-Based Testing with PropEr, Erlang, and Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.