gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:42:25 25 4
gpt4 key购买 nike

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

最佳答案

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

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

关于haskell - 如何使用 tasty-quickcheck 检查 monadic IO 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44572548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com