1

How do I specify test suites in HSpec? I'm going to have multiple *.hs test files for each of my modules and I want to just run stack test and for all of the tests to run. How do I set that up?

I tried to list the test modules like this in my cabal file but it doesn't work:

test-suite foo-test
  type:                exitcode-stdio-1.0
  hs-source-dirs:      test
  main-is:             Spec.hs
                     , Mod1Spec.hs
  build-depends:       base
                     , containers >= 0.5.6.2
                     , hqfl
                     , hspec >= 2.2.3
                     , hspec >= 2.2.3
                     , mtl >= 2.2.1
                     , pipes >= 4.1.8
                     , random >= 1.1
  ghc-options:         -threaded -rtsopts -with-rtsopts=-N
  default-language:    Haskell2010
2
  • why don't you use one of the stack templates? - btw: what exactly does not work - do you get an error message or something? Can you run your tests in ghci? Commented Jun 4, 2016 at 12:11
  • there's no error message - I just want all the specs to run automatically when I run stack test. At the moment it does not find any of the other specs apart from Spec.hs which I have specified in the cabal file. Commented Jun 4, 2016 at 12:54

1 Answer 1

5

Here is some docs on hspec testing:

http://hspec.github.io/hspec-discover.html

If your main spec module contains just the lines:

{-# OPTIONS_GHC -F -pgmF hspec-discover #-}

hspec-discover will scan the directory tree for spec tests.

Also - here is a small hspec example:

https://github.com/hspec/hspec-example

Sign up to request clarification or add additional context in comments.

2 Comments

I added the above to my test/Specs.hs file as you have done in your example. I changed my cabal file back to Specs.hs being my main file. When I run stack test it does not pick up my other test module located in test/Foo.hs.
finally got it working - I had to have the same directory layout in my test directory as my src directory.