quickCheck package:QuickCheck

Tests a property and prints the results to stdout. By default up to 100 tests are performed, which may not be enough to find all bugs. To run more tests, use withMaxSuccess. If you want to get the counterexample as a Haskell value, rather than just printing it, try the quickcheck-with-counterexamples package.
Automatic testing of Haskell programs QuickCheck is a library for random testing of program properties. The programmer provides a specification of the program, in the form of properties which functions should satisfy, and QuickCheck then tests that the properties hold in a large number of randomly generated cases. Specifications are expressed in Haskell, using combinators provided by QuickCheck. QuickCheck provides combinators to define properties, observe the distribution of test data, and define test data generators. Most of QuickCheck's functionality is exported by the main Test.QuickCheck module. The main exception is the monadic property testing library in Test.QuickCheck.Monadic. If you are new to QuickCheck, you can try looking at the following resources: The quickcheck-instances companion package provides instances for types in Haskell Platform packages at the cost of additional dependencies.
The QuickCheck manual gives detailed information about using QuickCheck effectively. You can also try https://begriffs.com/posts/2017-01-14-design-use-quickcheck.html, a tutorial written by a user of QuickCheck. To start using QuickCheck, write down your property as a function returning Bool. For example, to check that reversing a list twice gives back the same list you can write:
import Test.QuickCheck

prop_reverse :: [Int] -> Bool
prop_reverse xs = reverse (reverse xs) == xs
You can then use QuickCheck to test prop_reverse on 100 random lists:
>>> quickCheck prop_reverse
+++ OK, passed 100 tests.
To run more tests you can use the withMaxSuccess combinator:
>>> quickCheck (withMaxSuccess 10000 prop_reverse)
+++ OK, passed 10000 tests.
To use QuickCheck on your own data types you will need to write Arbitrary instances for those types. See the QuickCheck manual for details about how to do that. When testing fails quickCheck will try to give you a minimal counterexample to your property: @ import Test.QuickCheck prop_reverse_bad :: [Int] -> Bool prop_reverse_bad xs = reverse xs == xs
>>> quickCheck prop_reverse_bad
*** Failed! Falsified (after 3 tests and 3 shrinks):
[0,1]
@
However, beware because not all properties that ought to fail will fail when you expect them to:
>>> quickCheck $  x y -> x == y
+++ Ok, passed 100 tests.
That's because GHCi will default any type variables in your property to (), so in the example above quickCheck was really testing that () is equal to itself. To avoid this behaviour it is best practise to monomorphise your polymorphic properties when testing:
>>> quickCheck $  x y -> (x :: Int) == y
*** Failed! Falsified (after 4 tests and 3 shrinks):
0
1
Test all properties in the current module. The name of the property must begin with prop_. Polymorphic properties will be defaulted to Integer. Returns True if all tests succeeded, False otherwise. To use quickCheckAll, add a definition to your module along the lines of
return []
runTests = $quickCheckAll
and then execute runTests. Note: the bizarre return [] in the example above is needed on GHC 7.8 and later; without it, quickCheckAll will not be able to find any of the properties. For the curious, the return [] is a Template Haskell splice that makes GHC insert the empty list of declarations at that point in the program; GHC typechecks everything before the return [] before it starts on the rest of the module, which means that the later call to quickCheckAll can see everything that was defined before the return []. Yikes!
Tests a property, produces a test result, and prints the results to stdout.
Tests a property, using test arguments, and prints the results to stdout.
Tests a property, using test arguments, produces a test result, and prints the results to stdout.
Test a polymorphic property, defaulting all type variables to Integer. Invoke as $(polyQuickCheck 'prop), where prop is a property. Note that just evaluating quickCheck prop in GHCi will seem to work, but will silently default all type variables to ()! $(polyQuickCheck 'prop) means the same as quickCheck $(monomorphic 'prop). If you want to supply custom arguments to polyQuickCheck, you will have to combine quickCheckWith and monomorphic yourself. If you want to use polyQuickCheck in the same file where you defined the property, the same scoping problems pop up as in quickCheckAll: see the note there about return [].