测试 IO return 值
Testing of IO return value
我有一个声明,我需要检查 return 值:
> let a = tRunUmeQuery (selectByCount "Word" "Acoustic" "=" ((toInteger 1):[]) Strict) testdb
> :t a
a :: IO [[SqlValue]]
所以,我想确保 a
是一个长度恰好为 6 的列表(然后是 IO 6
)。
> fmap length a
6
检查这个的测试用例会是什么样子?
抱歉,解决方案并没有那么复杂(我只是想办法把它弄复杂)。
ucg :: TestTree
ucg = testGroup "selectByCount"
[ testCase "2 Words dominated by exactly 1 Acoustic" $ do
r <- fmap length $ tRunUmeQuery (selectByCount "Word" "Acoustic" "=" ((toInteger 1):[]) Strict) testdb
assertEqual "selectByCount: 1 Acoustic in Word" 6 r
]
这个测试组工作得很好。
我有一个声明,我需要检查 return 值:
> let a = tRunUmeQuery (selectByCount "Word" "Acoustic" "=" ((toInteger 1):[]) Strict) testdb
> :t a
a :: IO [[SqlValue]]
所以,我想确保 a
是一个长度恰好为 6 的列表(然后是 IO 6
)。
> fmap length a
6
检查这个的测试用例会是什么样子?
抱歉,解决方案并没有那么复杂(我只是想办法把它弄复杂)。
ucg :: TestTree
ucg = testGroup "selectByCount"
[ testCase "2 Words dominated by exactly 1 Acoustic" $ do
r <- fmap length $ tRunUmeQuery (selectByCount "Word" "Acoustic" "=" ((toInteger 1):[]) Strict) testdb
assertEqual "selectByCount: 1 Acoustic in Word" 6 r
]
这个测试组工作得很好。