短版:可以在Tasty-quickcheck中使用quickCheckAll
功能吗?
长版:
quickCheckAll
函数测试当前模块中以prop_
开头的所有属性,如下例所示:
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Test.QuickCheck ( quickCheckAll )
prop_1 :: Int -> Bool
prop_1 x = x + x == 2 * x
prop_2 :: Int -> Int -> Bool
prop_2 x y = x + y == y + x
-- Template Haskell hack to make the following $quickCheckAll work
-- under GHC >= 7.8.
return []
-- All properties as collected by 'quickCheckAll'.
runTests :: IO Bool
runTests = $quickCheckAll
main :: IO ()
main = runTests >> return ()
另一方面,我可以通过Tasty-quickcheck软件包在Tasty测试框架中使用QuickCheck,如下例所示:
module Main where
import Test.Tasty ( defaultMain, testGroup, TestTree )
import qualified Test.Tasty.QuickCheck as QC
prop_1 :: Int -> Bool
prop_1 x = x + x == 2 * x
prop_2 :: Int -> Int -> Bool
prop_2 x y = x + y == y + x
tests :: TestTree
tests = testGroup "Tested by QuickCheck"
[ QC.testProperty "prop_1" prop_1
, QC.testProperty "prop_2" prop_2
]
main :: IO ()
main = defaultMain tests
可以使用上面示例中的quickCheckAll
函数来避免显式列出使用QuickCheck和Tasty时的所有属性吗?
版本:以上示例使用GHC 8.2.2,QuickCheck 2.10.1和tasty-quickcheck 0.9.1进行测试。
答案 0 :(得分:2)
quickCheckAll
似乎无法实现,但底层逻辑可以通过测试框架重用。 Here's a new PR to get all properties in a list.