QuickCheck
You can use sandwich-quickcheck
(provided as a separate package) to easily integrate integrate QuickCheck tests into the test tree.
Haddocks can be found here.
Usage
To use sandwich-quickcheck
, just add the package to your project. Then, introduce a QuickCheck argument context using introduceQuickCheck. Now you can start writing props as test nodes using the prop function. For example:
quickCheckDemo :: TopSpec
quickCheckDemo = describe "QuickCheck tests" $ introduceQuickCheck $ do
prop "List reversal" $ \(xs :: [Int]) -> reverse (reverse xs) == xs
prop "Failing list reversal" $ \(xs :: [Int]) -> (reverse xs) == xs
Modifying the args
If you use introduceQuickCheck', you can pass your own value for the QuickCheck Args. The default version uses stdArgs.
If you want to modify the already-introduced arguments in a test tree, we provide the modifyArgs function, as well as helpers like modifyMaxSize
, modifyMaxDiscardRatio
, etc. These are modelled directly after HSpec's Test.Hspec.QuickCheck.
Controlling QuickCheck parameters with command line args
Some QuickCheck parameters can be controlled via the command line. To see the valid options, run Sandwich with --print-quickcheck-flags
.
Usage: demo [--quickcheck-seed INT]
[--quickcheck-max-discard-ratio INT]
[--quickcheck-max-size INT] [--quickcheck-max-success INT]
[--quickcheck-max-shrinks INT]
Available options:
--quickcheck-seed INT QuickCheck seed
--quickcheck-max-discard-ratio INT
Maximum number of discarded tests per successful test
before giving up
--quickcheck-max-size INT
Size to use for the biggest test cases
--quickcheck-max-success INT
Maximum number of successful tests before succeeding
--quickcheck-max-shrinks INT
Maximum number of shrinks before giving up