September 2016
Intermediate to advanced
408 pages
9h 18m
English
There are many libraries for testing Haskell code. Besides classic unit tests with HUnit and spec testing in Ruby-style with Hspec, we can verify properties using SmallCheck and QuickCheck with exhaustive and randomized test cases, respectively.
With QuickCheck we can test properties in a randomized fashion. We don't need to generate the test cases ourselves, as QuickCheck takes care of that. Here's a quick example of testing a simple arithmetic property:
stack ghci --package QuickCheck > import Test.QuickCheck as QC > QC.quickCheck $ \x y -> x > 0 ==> x + y >= y
All testable properties in QuickCheck are given as instances of the Testable class. As a quick reference, the core interface looks like this: ...
Read now
Unlock full access