quickcheck icon indicating copy to clipboard operation
quickcheck copied to clipboard

Property setup/teardown support?

Open saurabhnanda opened this issue 9 years ago • 4 comments

Already asked this on Stackoverflow AND Reddit, but no one seems to know.

I've been trying to solve the problem for the past 3 days now, but no matter what I try, the types don't compose elegantly.

saurabhnanda avatar Jul 31 '16 12:07 saurabhnanda

@saurabhnanda have you looked at Test.QuickCheck.Monadic.monadicIO? Here's a little example:

example :: Integer -> Property
example x = monadicIO $ do
    _ <- run $ do
        print x
        -- this is all in IO, so you could connect to a database,
        -- and do whatever you want
    assert True

reiddraper avatar Aug 01 '16 14:08 reiddraper

@reiddraper do take a look at http://stackoverflow.com/a/38684717/534481 ? Isn't that a better way?

saurabhnanda avatar Aug 01 '16 16:08 saurabhnanda

@saurabhnanda yeah, looks like that should work fine, too. I was only intending to show a basic example of performing IO during a test.

reiddraper avatar Aug 01 '16 18:08 reiddraper

http://stackoverflow.com/a/38684717/534481 looks good to me. Unfortunately there is currently no way to associate setup/teardown code with a property, so indeed you have to create the database connection outside of QuickCheck and pass it to your properties.

nick8325 avatar Aug 03 '16 16:08 nick8325