【问题标题】:Testing of IO return valueIO返回值测试
【发布时间】:2015-03-21 13:58:52
【问题描述】:

我有一个语句需要检查返回值:

> let a = tRunUmeQuery (selectByCount "Word" "Acoustic" "=" ((toInteger 1):[]) Strict)  testdb
> :t a 
a :: IO [[SqlValue]]

所以,我想确保 a 是一个长度正好为 6 的列表(然后是 IO 6)。

> fmap length a
6

检查这个的 testCase 是什么样的?

【问题讨论】:

    标签: unit-testing haskell testing io


    【解决方案1】:

    抱歉,解决方案并没有那么复杂(我只是想办法让它变得复杂)。

    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
        ]
    

    这个 TestGroup 工作得很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多