Hspec: A Testing Framework for Haskell

Running Tests with Hspec

The most common way to run a spec is with hspec, e.g.:

main = hspec spec

It is possible to customize how a spec is run by providing command-line flags. You can get a list of supported flags by passing --help to your test driver:

runhaskell Spec.hs --help
Usage: Spec.hs [OPTION]...

OPTIONS
                --help              display this help and exit
  -m PATTERN    --match=PATTERN     only run examples that match given PATTERN
                --skip=PATTERN      skip examples that match given PATTERN
                --color             colorize the output
                --no-color          do not colorize the output
  -f FORMATTER  --format=FORMATTER  use a custom formatter; this can be one of:
                                       specdoc
                                       progress
                                       failed-examples
                                       silent
  -o FILE       --out=FILE          write output to a file instead of STDOUT
                --depth=N           maximum depth of generated test values for
                                    SmallCheck properties
  -a N          --qc-max-success=N  maximum number of successful tests before a
                                    QuickCheck property succeeds
                --qc-max-size=N     size to use for the biggest test cases
                --qc-max-discard=N  maximum number of discarded tests per
                                    successful test before giving up
                --seed=N            used seed for QuickCheck properties
                --print-cpu-time    include used CPU time in summary
                --dry-run           pretend that everything passed; don't verify
                                    anything
                --fail-fast         abort on first failure
  -r            --rerun             rerun all examples that failed in the
                                    previously test run (only works in GHCi)
  -j N          --jobs=N            run at most N parallelizable tests
                                    simultaneously (default: number of available
                                    processors)

Using hspecWith instead of hspec gives even more control over how a spec is run.