问题
...instead of generating 100 new random samples for each property?
My testsuite contains the TemplateHaskell hack explained here [1] to test all functions named prop_*. Running the test program prints
=== prop_foo from tests/lala.lhs:20 ===
+++ OK, passed 100 tests.
=== prop_bar from tests/lala.lhs:28 ===
+++ OK, passed 100 tests.
and it looks like going through 100 random samples for each of the properties.
Problemis: Generating the samples is quite expensive, checking the properties is not. So I'd like to have a means to pass each random sample to each of the prop_* functions instead of creating new (#properties * 100) many samples.
Is there anything like that built in? Actually, I think I'd need a replacement for the splice
$(forAllProperties)
in
main :: IO ()
main
= do args <- parseArgs <$> getArgs
s <- $(forAllProperties) $ quickCheckWithResult args
s ? return () $ exitFailure
where
parseArgs as
= null as ? stdArgs $ stdArgs{ maxSuccess = read $ head as }
[1] Simple haskell unit testing, and QuickCheck exit status on failures, and cabal integration
回答1:
In this post you can see how to group tests
Stackoverflow post
That user provides a very simple example of use Test.Tasty.QuickCheck
Using testProperty and testGroup you can pass each random sample to each property
In the next link you can check the hackage of this package
Test.Tasty.QuickCheck
来源:https://stackoverflow.com/questions/38233443/how-can-quickcheck-test-all-properties-for-each-sample