2017-06-15 53 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_)