いつも忘れるのでHaskellのテストの最小のひな型をメモ
package.yaml
tasty
だけでなくtasty
から利用するテストパッケージもdependencies
に追加する。(これを忘れていつも嵌る)
tests: testproj-test: main: Test.hs source-dirs: test ghc-options: - -threaded - -rtsopts - -with-rtsopts=-N dependencies: - testproj - tasty - tasty-discover - tasty-hunit - tasty-hspec - tasty-quickcheck - tasty-smallcheck - bytestring
Hspec
のひな型
テストされる側のファイルとテストファイルは同じ名前にはできない。
s
は小文字
module Foo.Bar.TestBuzz where -- test import Test.Tasty import Test.Tasty.Hspec -- my library import Foo.Bar.Buzz getContext = return "dummy" spec_template = do before getContext $ do describe "some descriptions" $ do it "descripe it" $ \_-> True `shouldBe` True
ghci
をテスト側で呼び出す
stack ghci :testproj-test
実行方法
*> hspec spec_template some descriptions descripe it FAILED [1] Failures: test\Foo\Bar\TestBuzz.hs:17: 1) some descriptions descripe it expected: True but got: False Randomized with seed 285726028 Finished in 0.0081 seconds 1 example, 1 failure *** Exception: ExitFailure 1