How do you run a single test with QuickCheck when using monadicIO in Haskell?

108 Views Asked by At

I am using QuickCheck as a test suite in Haskell. I want to run a single test that is always the same in the IO Monad.

The problem is that QuickCheck generates 100 tests automatically even though the test does not take any parameters. As an example (not my actual test):

prop_parseTest :: Property
prop_parseTest = monadicIO $ do
  run $ writeFile "temp.txt" "hello world!"
  content <- run $ readFile "temp.txt"
  assert $ content == "hello world!"

How can I tell QuickCheck to only run this test once?

Edit: My tests are executed via the quickCheckAll function:

return []
runTests = $quickCheckAll

main :: IO ()
main = qcTests runTests

qcTests :: IO Bool -> IO ()
qcTests tests = do
  passed <- tests
  if passed then exitSuccess
            else exitFailure
1

There are 1 best solutions below

2
On BEST ANSWER

Test.QuickCheck.once

Modifies a property so that it only will be tested once.

You can use it like this:

prop_parseTest = once $ monadicIO $ do
    ...