【问题标题】:How to make Test-Framework to report about the reason of QuickCheck's fail?如何使 Test-Framework 报告 QuickCheck 失败的原因?
【发布时间】:2013-02-12 23:31:48
【问题描述】:

例如我有一个这样的测试代码:

import Data.Decimal
import Data.Ratio
import Data.Word
import Test.HUnit
import Control.Applicative

import Debug.Trace

import Test.QuickCheck
import qualified Test.QuickCheck.Property as P
import Test.Framework as TF (defaultMain, testGroup, Test)
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2 (testProperty)

...........

isEQ :: (Eq a, Show a) => a -> a -> P.Result
isEQ a b = if a == b
           then P.succeeded
           else P.failed {P.reason = show a ++ "\nis not equal to \n" ++ show b}

-- | "read" is the inverse of "show".
-- 
-- > read (show n) == n
prop_readShow :: Decimal -> P.Result
prop_readShow d =  isEQ (read (show d)) d

......

tests = [
        testGroup "QuickCheck Data.Decimal" [
                testProperty "readShow"           prop_readShow,
                testProperty "readShowPrecision"  prop_readShowPrecision,
                testProperty "fromIntegerZero"    prop_fromIntegerZero, 

..................

test-framerowk 的报告是这样的

 dist/build/Main/Main -a2000   
QuickCheck Data.Decimal:
  readShow: [Failed]
Arguments exhausted after 0 tests
  readShowPrecision: [Failed]
Arguments exhausted after 0 tests
  fromIntegerZero: [Failed]

没有任何原因的失败。外观相同的 HSpec 测试会在报告中打印失败原因,但测试框架测试不会。

【问题讨论】:

  • 在我看来,QuickCheck 无法为测试生成任何可接受的参数。您可以为Decimal 发布您的Arbitrary 实例吗?但奇怪的是,QuickCheck 在 HSpec 下运行时设法找到了一个反例。你能发布 HSpec 输出吗?

标签: testing haskell test-framework


【解决方案1】:

这里可能的问题是 QuickCheck 在发现太多不合适的测试用例后放弃了。提高 topt_maximum_unsuitable_generated_tests 将使 QuickCheck 有更多机会找到可接受的案例并完成测试。

【讨论】:

    【解决方案2】:

    这是一个不同的问题,实际上 test-framework-0.8 有一个错误https://github.com/batterseapower/test-framework/issues/34 所以测试计数的高值(-a 参数)会导致失败。

    您只需要将测试框架的版本降低到 0.7。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-09
      • 1970-01-01
      • 1970-01-01
      • 2020-10-20
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      相关资源
      最近更新 更多