首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用tasty quickcheck检查一元IO属性?

如何使用tasty quickcheck检查一元IO属性?
EN

Stack Overflow用户
提问于 2017-06-16 00:26:25
回答 1查看 339关注 0票数 3

如何用tasty-quickcheck测试monadicIO属性?

代码语言:javascript
复制
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_)

错误:

代码语言:javascript
复制
testClientDB :: ConnectionPool -> Property
testClientDB dbPool = monadicIO $ do
  withResource dbPool $ \conn -> do
    (client :: BloatedClient) <- pick arbitrary
    client_ <- run $ insertModel conn client
    QCM.assert (client == client_)
EN

回答 1

Stack Overflow用户

发布于 2017-06-16 12:41:28

我有一些东西要编译,但并不美观。我仍然在寻找一种更简单的方法来编写基于DB的Quickcheck属性,其中连接是从池中挑选的(以便测试可以并行运行)。

代码语言:javascript
复制
testClientDB :: ConnectionPool -> Property
testClientDB dbPool = monadicIO $ do
  (client :: Client) <- pick arbitrary
  client_ <- run $ withResource dbPool $ \conn -> insertModel conn client
  QCM.assert (client == client_)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44572548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档