Testing with Tasty
SmallCheck, QuickCheck and HUnit
Section titled “SmallCheck, QuickCheck and HUnit”import Test.Tastyimport Test.Tasty.SmallCheck as SCimport Test.Tasty.QuickCheck as QCimport Test.Tasty.HUnit
main :: IO ()main = defaultMain tests
tests :: TestTreetests = testGroup "Tests" [smallCheckTests, quickCheckTests, unitTests]
smallCheckTests :: TestTreesmallCheckTests = testGroup "SmallCheck Tests" [ SC.testProperty "String length <= 3" $ \s -> length (take 3 (s :: String)) <= 3 , SC.testProperty "String length <= 2" $ -- should fail \s -> length (take 3 (s :: String)) <= 2 ]
quickCheckTests :: TestTreequickCheckTests = testGroup "QuickCheck Tests" [ QC.testProperty "String length <= 5" $ \s -> length (take 5 (s :: String)) <= 5 , QC.testProperty "String length <= 4" $ -- should fail \s -> length (take 5 (s :: String)) <= 4 ]
unitTests :: TestTreeunitTests = testGroup "Unit Tests" [ testCase "String comparison 1" $ assertEqual "description" "OK" "OK"
, testCase "String comparison 2" $ -- should fail assertEqual "description" "fail" "fail!" ]Install packages:
cabal install tasty-smallcheck tasty-quickcheck tasty-hunitRun with cabal:
cabal exec runhaskell test.hs