haskell - 测试框架 'plusTestOptions'和 'testProperty'

标签 haskell

我有一个单独的 QuickCheck2 属性,我想运行超过标准 100 次,但我一直不知道如何说服 Test.Framework使用plusTestOptions运行更多--testProperty失败并显示“0 次测试后参数耗尽”。

相关代码片段:

mkMsysTests :: TestArgs -> [Test]
mkMsysTests opts =
  [ testGroup "foo"
    [ plusTestOptions testOptions_more (testProperty "bar" prop_bar) ]
  ]

testOptions_more =
  TestOptions { topt_seed = Nothing
              , topt_maximum_unsuitable_generated_tests = Nothing
              , topt_maximum_test_size = Just 500
              , topt_maximum_test_depth = Nothing
              , topt_timeout = Nothing
              , topt_maximum_generated_tests = Just 10000
              }

理论上,这应该测试该属性 10,000 次。但事实并非如此。是否有任何好的文档或示例演示如何使用 TestOptions运行属性测试超过标准 100 次?

最佳答案

答案是,必须增加不合适测试的数量 topt_maximum_unsuitable_ generated_tests,使其大于或等于生成测试的数量 topt_maximum_ generated_tests。另外,应该使用 mempty 实例并使用更新的记录成员对其进行修改。修改后的代码片段为:

import           Data.Monoid (mempty)
import           Test.Framework (Test, defaultMainWithArgs, plusTestOptions, testGroup)
import           Test.Framework.Options               (TestOptions' (..))
import           Test.Framework.Providers.HUnit       (testCase)
import           Test.Framework.Providers.QuickCheck2 (testProperty)
import           Test.HUnit                           (Assertion, assertBool, assertFailure)
import           Test.QuickCheck                      (Property, choose, forAll)

{- list of tests -}
mkMsysTests :: TestArgs -> [Test]
mkMsysTests opts =
  [ testGroup "foo"
    [ plusTestOptions testOptions_more (testProperty "bar" prop_bar) ]
  ]

testOptions_more =
  mempty { topt_maximum_unsuitable_generated_tests = Just 10000
         , topt_maximum_generated_tests = Just 10000
         }

我没有一个很好的解释,为什么如果不合适的测试数量少于生成的测试数量,Test.Framework 代码就会放弃;我只是对代码进行了快速的“眼球”扫描并注意到了修复。

关于haskell - 测试框架 'plusTestOptions'和 'testProperty',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41133195/

相关文章:

c - GHC 运行时如何处理文件 I/O?

json - 如何在 Yesod 中编写一个接收文件/图像上传的 JSON 端点?

haskell - 为什么 (Haskell) Repa 只使用一个 CPU?

haskell - Monads(Haskell)的主要目的

haskell - 没有数据构造函数的数据声明。可以实例化吗?为什么会编译?

haskell - `until` 是如何工作的?

haskell - 程序获取一个对的列表并将其从小到大排序返回

haskell - 如何从元组列表中获取元素列表?

haskell - Cabal 无法解析测试套件 block 中的构建依赖项

haskell - GHC TypeLits 没有值