testing - 测试.QuickCheck : speed up testing multiple properties for the same type

标签 testing haskell quickcheck htf

我正在测试一个生成我自己类型实例的随机生成器。为此,我有一个 Arbitrary 的自定义实例:

complexGenerator :: (RandomGen g) => g -> (MyType, g)

instance Arbitrary MyType where
    arbitrary = liftM (fst . complexGenerator . mkStdGen) arbitrary

这适用于 Test.QuickCheck(实际上是 Test.Framework),用于测试生成的值是否具有某些属性。但是,我要检查的属性相当多,添加的越多,验证它们所花费的时间就越多。

有没有办法使用相同的生成值来测试每个属性,而不是每次都重新生成它们?我显然仍然希望在失败时看到哪个属性不成立,因此使用制作一个巨大的属性并不是最佳选择。

最佳答案

I obviously still want to see, on failures, which property did not hold, so making one giant property with and is not optimal.

您可以使用 printTestCase 标记每个属性在用 conjoin build 一个巨大的属性(property)之前.

例如你认为这是个坏主意:

prop_giant :: MyType -> Bool
prop_giant x = and [prop_one x, prop_two x, prop_three x]

这将同样高效,但会为您提供更好的输出:

prop_giant :: MyType -> Property
prop_giant x = conjoin [printTestCase "one" $ prop_one x,
                        printTestCase "two" $ prop_two x,
                        printTestCase "three" $ prop_three x]

(话虽如此,我自己从未使用过这种方法,只是假设它会起作用;conjoin 可能出于某种原因在文档中被标记为实验性的。)

关于testing - 测试.QuickCheck : speed up testing multiple properties for the same type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15317041/

相关文章:

ruby-on-rails - 网址验证 rails

android - 带有 minSdkVersion 9 的项目中的 UI Automator

haskell IO : convert IO String to "Other type"

haskell - 自动收集所有快速检查

node.js - 使用 mocha/supertest 测试随机值

haskell - 添加元素的函数式编程风格的映射函数?

haskell - Happy 中的 %% 是什么意思?

php - PHP 中基于属性的测试?

haskell - 如何使用 QuickCheck 为 StateT 编写测试

testing - 使用竞争检测器时可以跳过特定测试吗?