- Home
- Unit Testing
- Hspec
Hspec
What it is
Hspec is a free testing framework for Haskell, available as a Cabal source package on Hackage and listed under the MIT license. Its domain-specific language organizes examples in nested `describe` and `it` blocks, with expectations for equality, predicates, and exceptions. Hspec can run QuickCheck properties as examples, integrate with SmallCheck, and run existing HUnit test suites; HUnit assertions can also be used in specs. The `hspec-discover` preprocessor scans spec files and generates test-driver boilerplate. Its automatic discovery convention expects filenames ending in `Spec.hs` and a top-level `spec` binding. Runner options include filtering or skipping examples, randomizing their order, failing fast, rerunning failures, and choosing a formatter. Configuration can come from `~/.hspec`, a project `.hspec` file, environment variables, or command-line arguments, with command-line options taking precedence. The manual documents passing options through Cabal, Stack, and GHCi. Specs marked `parallel` can run across multiple CPUs when linked with `-threaded` and run with `+RTS -N -RTS`.
For and against
For
- Integrates with QuickCheck, SmallCheck, and HUnit.
- Can generate test-driver boilerplate from spec files.
- Runner offers filtering, randomization, and reruns.
- Supports parallel specs with the documented runtime setup.
Against
- Automatic discovery expects `Spec.hs` filenames and a top-level `spec` binding.
- Parallel execution requires the documented threaded setup.
The verdict
Hspec brings organized specifications, property testing, and HUnit compatibility to Haskell projects. It is listed as free, with source distribution available on Hackage.
Who it suits
Hspec suits Haskell developers who want to organize example tests and property checks in one framework. Its discovery tool may help projects that follow the documented spec-file naming and export convention.
Plans and prices
Hspec
Haskell testing framework · source package available on Hackage
Read 9 Oct 2026 · hspec.github.io
On the record
- Configuration
- Hspec can read options from `~/.hspec`, a project `.hspec` file, environment variables, or command-line arguments, with command-line options taking highest precedence.hspec.github.io · read 9 Oct 2026
- Discovery
- The `hspec-discover` tool can generate a test driver for automatically discovered spec files.hspec.github.io · read 9 Oct 2026
- Discovery convention
- Hspec's automatic discovery expects spec files to end in `Spec.hs` and export a top-level `spec` binding.hspec.github.io · read 8 Oct 2026
- Distribution
- The Hspec package is available as a Cabal source package from Hackage.hackage.haskell.org · read 9 Oct 2026
- Expectations
- Hspec includes combinators for equality, predicates, and expected exceptions.hspec.github.io · read 9 Oct 2026
- HUnit compatibility
- Hspec can run existing HUnit test suites, and HUnit assertions can be used in Hspec specs.hspec.github.io · read 8 Oct 2026
- Integrations
- Hspec integrates with QuickCheck, SmallCheck, and HUnit.hspec.github.io · read 8 Oct 2026
- Legacy tests
- Hspec can run existing HUnit tests alongside ordinary spec items through `fromHUnitTest` from `hspec-contrib`.hspec.github.io · read 9 Oct 2026
- License
- The GitHub repository identifies the project license as MIT.github.com · read 9 Oct 2026
- Maker and headquarters
- The opened Hspec pages identify Hspec as a project but do not state a maker organization or headquarters.hspec.github.io · read 9 Oct 2026
- Parallel execution
- Specs can be marked for parallel execution to use multiple CPUs; the documented example links with `-threaded` and runs with `+RTS -N -RTS`.hspec.github.io · read 9 Oct 2026
- Property testing
- Hspec can run QuickCheck properties as test examples.hspec.github.io · read 8 Oct 2026
- Purpose
- Hspec is a testing framework for Haskell.hspec.github.io · read 9 Oct 2026
- Supported build tools
- The manual documents passing Hspec options through Cabal, Stack, and GHCi.hspec.github.io · read 9 Oct 2026
- Test controls
- Runner options include matching or skipping examples, randomizing execution order, failing fast, rerunning failures, and choosing a formatter.hspec.github.io · read 9 Oct 2026
- Test descriptions
- Hspec provides a domain-specific language for organizing tests with nested `describe` and `it` blocks.hspec.github.io · read 8 Oct 2026
- Test discovery
- The `hspec-discover` preprocessor scans for spec files and generates test driver boilerplate.hspec.github.io · read 8 Oct 2026
- Test DSL
- Hspec provides a friendly DSL for defining and organizing tests with `describe` and `it`.hspec.github.io · read 9 Oct 2026