如何使用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_)
答案 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_)