QuickCheck- Automatic testing of Haskell programs




Property and Testable types

class Testable prop whereSource

The class of things which can be tested, i.e. turned into a property.


property :: prop -> PropertySource


Testable Bool 
Testable () 
Testable Result 
Testable Prop 
Testable prop => Testable (Gen prop) 
(Arbitrary a, Show a, Testable prop) => Testable (a -> prop) 

Type Prop

newtype Prop Source




unProp :: Rose (IO Result)


type Rose

data Rose a Source


MkRose a [Rose a] 


join :: Rose (Rose a) -> Rose aSource

Result type

data Callback Source

Different kinds of callbacks


PostTest (State -> Result -> IO ())

Called just after a test

PostFinalFailure (State -> Result -> IO ())

Called with the final failing test-case

data Result Source

The result of a single test.




ok :: Maybe Bool

result of the test case; Nothing = discard

expect :: Bool

indicates what the expected result of the property is

reason :: String

a message indicating what went wrong

stamp :: [(String, Int)]

the collected values for this test case

callbacks :: [Callback]

the callbacks for this test case


Lifting and mapping functions

mapResult :: Testable prop => (Result -> Result) -> prop -> PropertySource

mapIOResult :: Testable prop => (IO Result -> IO Result) -> prop -> PropertySource

mapProp :: Testable prop => (Prop -> Prop) -> prop -> PropertySource

Property combinators

mapSize :: Testable prop => (Int -> Int) -> prop -> PropertySource

Changes the maximum test case size for a property.



:: Testable prop 
=> (a -> [a])

shrink-like function.

-> a

The original argument

-> (a -> prop) 
-> Property 

Shrinks the argument to property if it fails. Shrinking is done automatically for most types. This is only needed weh you want to override the default behavior.

callback :: Testable prop => Callback -> prop -> PropertySource

Adds a callback

whenFail :: Testable prop => IO () -> prop -> PropertySource

Performs an IO action after the last failure of a property.

whenFail' :: Testable prop => IO () -> prop -> PropertySource

Performs an IO action every time a property fails. Thus, if shrinking is done, this can be used to keep track of the failures along the way.

expectFailure :: Testable prop => prop -> PropertySource

Modifies a property so that it is expected to fail for some test cases.

label :: Testable prop => String -> prop -> PropertySource

Attaches a label to a property. This is used for reporting test case distribution.

collect :: (Show a, Testable prop) => a -> prop -> PropertySource

Labels a property with a value:

 collect x = label (show x)



:: Testable prop 
=> Bool

True if the test case should be labelled.

-> String


-> prop 
-> Property 

Conditionally labels test case.



:: Testable prop 
=> Bool

True if the test case belongs to the class.

-> Int

The required percentage (0-100) of test cases.

-> String

Label for the test case class.

-> prop 
-> Property 

Checks that at least the given proportion of the test cases belong to the given class.

(==>) :: Testable prop => Bool -> prop -> PropertySource

Implication for properties: The resulting property holds if the first argument is False, or if the given property holds.

within :: Testable prop => Int -> prop -> PropertySource

Considers a property failed if it does not complete within the given number of microseconds.

forAll :: (Show a, Testable prop) => Gen a -> (a -> prop) -> PropertySource

Explicit universal quantification: uses an explicitly given test case generator.

forAllShrink :: (Show a, Testable prop) => Gen a -> (a -> [a]) -> (a -> prop) -> PropertySource

Like forAll, but tries to shrink the argument for failing test cases.

(.&.) :: (Testable prop1, Testable prop2) => prop1 -> prop2 -> PropertySource