如何用tasty-quickcheck测试monadicIO属性?
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_)发布于 2017-06-16 12:41:28
我有一些东西要编译,但并不美观。我仍然在寻找一种更简单的方法来编写基于DB的Quickcheck属性,其中连接是从池中挑选的(以便测试可以并行运行)。
testClientDB :: ConnectionPool -> Property
testClientDB dbPool = monadicIO $ do
(client :: Client) <- pick arbitrary
client_ <- run $ withResource dbPool $ \conn -> insertModel conn client
QCM.assert (client == client_)https://stackoverflow.com/questions/44572548
复制相似问题