Here is a setting for a directory structure like this
> tree
.
βββ example.cabal
βββ app
β βββ Main.hs
βββ ChangeLog.md
βββ LICENSE
βββ Setup.hs
βββ src
β βββ A
β β βββ C.hs
β βββ A.hs
β βββ B.hs
βββ stack.yaml
βββ tst
βββ integration
β βββ Spec.hs
βββ unit
βββ A
β βββ CSpec.hs
βββ ASpec.hs
βββ BSpec.hs
βββ Spec.hs
you want to have integration tests, which are separated from regular unit tests and several sub-modules, each module corresponding to src
-pamyatke
first of all you need to add test packages to
example.cabal
file
name: example
...
-- copyright:
-- category:
build-type: Simple
extra-source-files: ChangeLog.md
cabal-version: >=1.10
executable testmain
main-is: Main.hs
hs-source-dirs: app
build-depends: base
, example
library
exposed-modules: A.C,A,B
-- other-modules:
-- other-extensions:
build-depends: base >=4.9 && <4.10
hs-source-dirs: src
default-language: Haskell2010
test-suite unit-tests
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: tst/unit
build-depends: base
, example
, hspec
, hspec-discover
, ...
test-suite integration-tests
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs: tst/integration
build-depends: base
, example
, hspec
, ...
put the following in tst/unit/Spec.hs
from hspec-discover
and discovers (hence the name) all modules of the form ...Spec.hs
and performs a function spec
from each of these modules.
tst/unit/Spec.hs
{-
only this single line
Other test files
then add your unit tests to ASpec.hs
, and others to BSpec.hs
, CSpec.hs
and yours Spec.hs
to the foldertst/integration
module ASpec where
import Test.Hspec
import A
spec :: Spec
spec = do
describe "Prelude.head" $ do
it "returns the first element of a list" $ do
head [23 ..] `shouldBe` (23 :: Int)
it "returns the first element of an *arbitrary* list" $
property $ \x xs -> head (x:xs) == (x :: Int)
it "throws an exception if used with an empty list" $ do
evaluate (head []) `shouldThrow` anyException
you can compile and run your tests with
$> stack test
$> stack test :unit-tests
$> stack test :integration-tests
Sources
https://hspec.imtqy.com, hspec-, , . - https://haskellstack.org - / - .
haskell . HUnit, QuickCheck, Smallcheck, doctests ( , - , ).