The Batch
module of QuickCheck was removed with version 2 (1.2.0.1 still has it). Because of this, I'm always feeling like mapM_
-ing multiple tests together is kind of hacky. Am I overlooking the successor feature in QuickCheck 2? Is there a canonical way of grouping independent tests together?
QuickCheck 2 batch processing
Asked Answered
There's the 'go big or go home' option of grouping together all tests in the current module via Test.QuickCheck.All
. It requires Template Haskell, and all properties must begin with prop_
. Ex:
{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck.All
prop_one, prop_two :: a -> Bool
prop_one = const True
prop_two = const True
runTests :: IO Bool
runTests = $quickCheckAll
main :: IO ()
main = runTests >>= \passed -> if passed then putStrLn "All tests passed."
else putStrLn "Some tests failed."
Two important notes: First, properties from imported modules don't seem to be included. Second, (and it looks very weird), in GHC 7.8 you need to insert
return []
before the line runTests = $quickCheckAll
. See the module haddock page for more information. –
Custos If you're testing through a cabal test-suite, this
main
would probably suit you better: main = runTests >>= \passed -> if passed then exitSuccess else exitFailure
. And you'll also need to import System.Exit(exitSuccess, exitFailure)
. –
Custos © 2022 - 2024 — McMap. All rights reserved.
test-framework
andtest-framework-quickcheck2
. – Italia