Introduction to Custom Generators
Explore how custom generators enhance property-based testing by focusing on limited edge cases and scenarios that default generators may miss. Understand the importance of gathering statistics within tests to detect subtle bugs. This lesson helps you apply these techniques to improve test accuracy and debugging confidence.
We'll cover the following...
Why use custom generators?
Until now, we have only used default generators in the properties that we have written. If we were to use these tools and techniques only, there is a chance that we could improve our tests by quite a bit.
In the previous chapter, we saw how to test an encoder and a decoder with symmetric properties. Say we suspected there was a bug whenever there are more than 255 elements in a map. 255 is a number that could hit the upper limits of what a byte can store.
To put it in other terms, the properties we’ve written so far have relied on fairly random generated data to act as inputs. The theory is that with enough random walks, we can eventually get into every nook and cranny of the code and find all the edge cases. But there’s no guarantee that ...