Re-centering with ?SHRINK
Explore how the ?SHRINK macro helps customize shrinking in property-based testing using PropEr. Understand its use in centering shrinking efforts on relevant data points, improving error localization. Learn to apply it for generators like timestamps, refining tests for realistic and simpler failure cases.
We'll cover the following...
?SHRINK
?SHRINK is conceptually the simplest of the two macros that can be used to impact shrinking. It is best used to pick a custom zero-point toward which PropEr will try to shrink data. We can do this mainly by giving the framework a normal generator for normal cases, and then suggesting it uses other simpler generators whenever an error is discovered.
The macro takes the form ?SHRINK(DefaultGenerator, [AlternativeGenerators]) in Erlang. The DefaultGenerator will be used for all passing tests. Once a property fails, however, ?SHRINK lets us tell PropEr that any of the alternative generators in the list are interesting ways to get simpler relevant data. We can give hints about how the framework should search for failures. And if the alternative generators are not fruitful, so be it. The ...