21

When i google for how to integrate unit tests with cabal files, i either find

How would you run all unit test using cabal (for example everytime i do a "cabal build") today?

LennyStackOverflow
  • 2,228
  • 1
  • 19
  • 22

1 Answers1

17
  1. Make sure you have the latest version of Cabal and cabal-install installed.

  2. Have a test-suite section in your .cabal file. See this section of cabal's documentation for an explanation of how to write a test-suite section in your Cabal file and this section for instructions on how to run it.

I've been using the built-in test support for some time and it has saved me from having to maintain fragile Makefiles just for my tests. There are still some rough edges in the command line output of cabal test, but they have been fixed in HEAD so in the next Cabal/cabal-install release everything should be very smooth.

Palmik
  • 2,675
  • 16
  • 13
tibbe
  • 8,809
  • 7
  • 36
  • 64
  • `cabal test` doesn't have test suite drivers for most frameworks yet, though... :( – alternative Jul 22 '11 at 13:05
  • 1
    Thanks. I am a bit unsure how HUnit and QuickCheck fit in there. – LennyStackOverflow Jul 22 '11 at 15:34
  • 1
    @Lenny222 They don't, yet. Use `defaultMainWithHooks` instead for the time being – alternative Jul 23 '11 at 23:09
  • 3
    Thanks guys. And how about "test-framework"? It would be really great if someone having a good overview over the current testing situation could find the time to write up a clarifying blog post or something. – LennyStackOverflow Jul 25 '11 at 07:11
  • 7
    I'll try to write a blog post soonish. The setup I use is to have a `test-suite` stanza of type `exitcode-stdio` and use test-framework (with its bindings to QC and HUnit) to write the actual test code. Look at: https://github.com/tibbe/hashable/blob/master/hashable.cabal and https://github.com/tibbe/hashable/blob/master/tests/Properties.hs – tibbe Aug 03 '11 at 07:55