Unit testing versus property-based testing
In this section, we’ll review unit testing, probably the most common and well-known form of software testing, and identify several important shortcomings. Then, we’ll introduce property-based testing and explain how it improves upon those shortcomings.
Unit testing
Unit testing is perhaps the most familiar and most obvious way of testing code, especially in the setting of functional programming.
In Haskell, the smallest meaningful unit of code that can be tested is a function. The way to test a function is to supply it with an input and see whether it produces the corresponding expected output. If not, there is either something wrong with the function’s implementation or with our understanding of how it should behave. Either way, we have identified a problem that needs to be investigated further.
Manual testing
With the GHCi
interactive shell, such unit testing often happens naturally. When we have written...