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_)
你见过Opaleye有吗一个你可以用来获取灵感的测试套件? https://github.com/tomjaguarpaw/haskell-opaleye/tree/master/Test –
@TomEllis你的意思是“灵感”以什么方式?在使用QC编写数据库测试时,我是否做了根本性错误?因为我似乎直接通过'QC.quickCheck'运行'testClientDB'。这只是它不与美味的'TestTree'构成# –
我的意思是如果你喜欢,你可以使用与Opaleye的QuickCheck测试用例相同的测试设置。这可能比试图发现你自己的方式更容易。尽管如此,我认为你并没有做任何根本性的错误。 –