test1 = hspec $ do
describe "blabla" $ do
it "should be equl" $ verbose $
\input-> ...
在上面的代码中,当测试失败时,它将打印失败的input
。但是我实际上对可以从input
计算出的另一个值感兴趣。我可以要求QuickCheck
打印其他值吗?
以某种方式我从未见过它的广告,但是您可以在hspec
属性中使用QuickCheck
的期望。这是一个例子:
describe "blabla" $ do
it "should be equl" $ verbose $ \input ->
round input `shouldBe` floor (input :: Double)
以上属性显然是不正确的,因此它应该失败。因为我们不仅对input
感兴趣,而且还想从中知道计算值,所以shouldBe
会给我们:
3) blabla should be equl
Falsifiable (after 2 tests and 4 shrinks):
0.6
expected: 0
but got: 1
[自然,由于verbose
,只有input
会通过测试通过,而计算值(例如round input
)只会针对失败的测试用例进行打印,这正是您想要的结果无论如何。