QuickCheck 2 batch processing
Asked Answered
E

1

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?

Electrician answered 23/11, 2012 at 17:35 Comment(1)
Look at test-framework and test-framework-quickcheck2.Italia
F
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."
Frequency answered 23/11, 2012 at 20:18 Comment(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 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.