2017-06-15 52 views
1

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

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

你见过Opaleye有吗一个你可以用来获取灵感的测试套件? https://github.com/tomjaguarpaw/haskell-opaleye/tree/master/Test –

+0

@TomEllis你的意思是“灵感”以什么方式?在使用QC编写数据库测试时,我是否做了根本性错误?因为我似乎直接通过'QC.quickCheck'运行'testClientDB'。这只是它不与美味的'TestTree'构成# –

+0

我的意思是如果你喜欢,你可以使用与Opaleye的QuickCheck测试用例相同的测试设置。这可能比试图发现你自己的方式更容易。尽管如此,我认为你并没有做任何根本性的错误。 –

回答

0

我得到的东西来编译,但它是不漂亮。我仍然在寻找一种更简单的方法来编写基于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_)