[英]How to check monadic IO properties with tasty-quickcheck?
一個人如何測試是否可以monadicIO財產美味,快速檢查 ? 我嘗試了以下操作,其中testCase
正常工作(來自HUnit),但testProperty
(來自testProperty
)未編譯。
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_)
我可以編譯一些東西,但這並不漂亮。 我仍在尋找一種更簡便的方法來編寫具有趣味的基於數據庫的Quickcheck屬性,該方法是從池中選擇連接的(以便可以並行運行測試)
testClientDB :: ConnectionPool -> Property
testClientDB dbPool = monadicIO $ do
(client :: Client) <- pick arbitrary
client_ <- run $ withResource dbPool $ \conn -> insertModel conn client
QCM.assert (client == client_)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.