如何使用Tasty-quickcheck检查monadic IO属性?

时间:2017-06-15 16:26:25

标签: haskell quickcheck

如何使用tasty-quickcheck测试monadicIO属性?我尝试了以下内容,其中testCase按预期工作(来自HUnit),但testProperty(来自QuickCheck)未编译。

import Test.Common
import Models.Client as Client
import Foundation
import Test.Foundation.Types ()
import Test.QuickCheck.Monadic as QCM
import Opaleye
import Data.Pool as P

tests :: ConnectionPool -> TestTree
tests dbPool = testGroup "All tests"
  [
    testProperty "Client DB" $ testClientDB dbPool
  , testCase "Existing client.properties in production" $ withResource dbPool testExistingClientProperties
  ]

testExistingClientProperties :: Connection -> Assertion
testExistingClientProperties = undefined -- REDACTED    


testClientDB :: ConnectionPool -> Property
testClientDB dbPool = monadicIO $ do
  withResource dbPool $ \conn -> do
    (client :: Client) <- pick arbitrary
    client_ <- run $ insertModel conn client
    QCM.assert (client == client_)

错误:

testClientDB :: ConnectionPool -> Property
testClientDB dbPool = monadicIO $ do
  withResource dbPool $ \conn -> do
    (client :: BloatedClient) <- pick arbitrary
    client_ <- run $ insertModel conn client
    QCM.assert (client == client_)

1 个答案:

答案 0 :(得分:0)

我有东西要编译,但它不漂亮。我仍然在寻找一种更简单的方法来编写基于数据库的Quickcheck属性,其中可以从池中选择连接(以便可以并行运行测试)

testClientDB :: ConnectionPool -> Property
testClientDB dbPool = monadicIO $ do
  (client :: Client) <- pick arbitrary
  client_ <- run $ withResource dbPool $ \conn -> insertModel conn client
  QCM.assert (client == client_)