11

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?

David
  • 8,275
  • 5
  • 26
  • 36
  • 3
    Look at [`test-framework`](http://hackage.haskell.org/package/test-framework) and [`test-framework-quickcheck2`](http://hackage.haskell.org/package/test-framework-quickcheck2). – dflemstr Nov 23 '12 at 17:43

1 Answers1

10

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."
jtobin
  • 3,253
  • 3
  • 18
  • 27
  • 2
    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](http://hackage.haskell.org/package/QuickCheck-2.7.6/docs/Test-QuickCheck-All.html) for more information. – MasterMastic Sep 11 '14 at 19:04
  • 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)`. – MasterMastic Sep 11 '14 at 19:09