我有一个单独的 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/