Question

Being a fan of quickCheck, I have a lot of

prop_something_something = ...

throughout my program.

For convenience, to easily run all of them, I define

runchecks = do
    quickCheck prop_something_something
    quickCheck prop_something_different

but is there a nice way to generate runchecks?

TL;DR: I want to easily run all quickChecks in a file. I guess one way is to prefix the runnable tests with test_ or something similar, but that might be too hacky.

Was it helpful?

Solution

You can do this with the test-framework-th package. Just do:

import Test.Framework.TH
import Test.Framework.Providers.QuickCheck2
runchecks = $(defaultMainGenerator)

This will use the test-framework way of running tests, i.e. you'll get slightly more information than what you'd get by simply running the tests one after the other, which oftentimes is a good thing.

You obviously need TemplateHaskell to be enabled for this to work; either add Default-extensions: TemplateHaskell to your Cabal file, or add {-# LANGUAGE TemplateHaskell #-} to the top of the file.

OTHER TIPS

An extra note: this functionality exists out of the box in QuickCheck 2 as well, see the function quickCheckAll, which requires an import of Test.QuickCheck.All as well as TemplateHaskell. quickCheckAll will test all functions in your module whose name starts with prop_.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top