Testing 如何使测试框架报告QuickCheck的原因';它失败了吗?
例如,我有这样一个测试代码:Testing 如何使测试框架报告QuickCheck的原因';它失败了吗?,testing,haskell,test-framework,Testing,Haskell,Test Framework,例如,我有这样一个测试代码: 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, te
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,
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,
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,
TestFrameRowk的报告如下所示
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测试在报告中打印失败原因,但测试框架测试没有打印失败原因。这是另一个问题,事实上test-framework-0.8有一个bug,因此测试计数的高值(-a参数)会导致失败
您只需要将测试框架的版本降低到0.7。这里可能存在的问题是,QuickCheck在发现太多不合适的测试用例后放弃了。提高
topt\u maximum\u unjustified\u generated\u tests
将使QuickCheck有更多机会找到可接受的案例,并允许测试完成。在我看来,QuickCheck无法为测试生成任何可接受的参数。你能把你的任意
实例发布到十进制
吗?但奇怪的是,QuickCheck在HSpec下运行时找到了一个反例。你能发布HSpec输出吗?