title: How to use HUnit in Stack
body: <p>I have a stackproject <code>stapro</code> with a file <code>app/Main.hs</code></p>
  
  <pre><code>module Main where
  
  import Lib
  
  main = putStrLn "This is main" 
  
  foo::Int -&gt;Int
  foo = (+1)
  </code></pre>
  
  <p>and a file <code>test/Spec.hs</code></p>
  
  <pre><code>module Spec where
  
  import Test.HUnit
  import Main (foo)
  
  main :: IO ()
  main = putStrLn "Test suite not yet implemented"
  
  testFoo :: Test
  testFoo = TestCase $ assertEqual "Should return 2" 2 (foo 1)
  </code></pre>
  
  <p>When I try to execute the tests however</p>
  
  <pre><code>$ stack test
  While constructing the BuildPlan the following exceptions were encountered:
  
  --  While attempting to add dependency,
      Could not find package Main in known packages
  
  --  Failure when adding dependencies:    
        Main: needed (-any), stack configuration has no specified version
      needed for package stapro-0.1.0.0
  </code></pre>
  
  <p>My .cabal file is</p>
  
  <pre><code>name:                stapro
  version:             0.1.0.0
  ...
  build-type:          Simple
  -- extra-source-files:
  cabal-version:       &gt;=1.10
  
  library
    hs-source-dirs:      src
    exposed-modules:     Lib
    build-depends:       base &gt;= 4.7 &amp;&amp; &lt; 5
    default-language:    Haskell2010
  
  executable stapro-exe
    hs-source-dirs:      app
    main-is:             Main.hs
    ghc-options:         -threaded -rtsopts -with-rtsopts=-N
    build-depends:       base
                       , stapro
    default-language:    Haskell2010
  
  test-suite stapro-test
    type:                exitcode-stdio-1.0
    hs-source-dirs:      test
    main-is:             Spec.hs
    build-depends:       base
                       , stapro
                       , HUnit
                       , Main
    ghc-options:         -threaded -rtsopts -with-rtsopts=-N
    default-language:    Haskell2010
  
  ...
  </code></pre>