| CARVIEW |
Select Language
HTTP/2 200
server: GitHub.com
content-type: text/html; charset=utf-8
last-modified: Mon, 08 Dec 2025 03:05:13 GMT
access-control-allow-origin: *
etag: W/"69364069-21bb"
expires: Fri, 16 Jan 2026 12:28:20 GMT
cache-control: max-age=600
content-encoding: gzip
x-proxy-cache: MISS
x-github-request-id: 1229:3D32E3:2E7FE:33CA2:696A2C89
accept-ranges: bytes
age: 0
date: Fri, 16 Jan 2026 12:18:20 GMT
via: 1.1 varnish
x-served-by: cache-bom-vanm7210036-BOM
x-cache: MISS
x-cache-hits: 0
x-timer: S1768565900.895499,VS0,VE236
vary: Accept-Encoding
x-fastly-request-id: 36babb7b410bbad2c956a24c18b32e9bb4321a3b
content-length: 2494
Hspec: A Testing Framework for Haskell
Hspec: A Testing Framework for Haskell
Contents
- Writing tests with Hspec
- Running tests with Hspec
- Passing options to Hspec
- Setting expectations
- Using QuickCheck with Hspec
- Interoperability with HUnit
- Automatic spec discovery
- Running individual spec items
- Speeding up the edit-compile-test cycle
- Parallel spec execution
- Extending Hspec: Writing a custom formatter
User's Manual
Hspec is a testing framework for Haskell. Some of Hspec's distinctive features are:
- a friendly DSL for defining tests
- integration with QuickCheck, SmallCheck, and HUnit
- parallel test execution
- automatic discovery of test files
Here is an example for the impatient:
cabal update && cabal install --package-env=. --lib hspec hspec-contrib QuickCheck HUnit
-- file Spec.hs
import Test.Hspec
import Test.QuickCheck
import Control.Exception (evaluate)
main :: IO ()
main = hspec $ 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` anyExceptionrunhaskell Spec.hs Prelude.head returns the first element of a list [✔] returns the first element of an *arbitrary* list [✔] +++ OK, passed 100 tests. throws an exception if used with an empty list [✔] Finished in 0.0005 seconds 3 examples, 0 failures
Contents
- Writing tests with Hspec
- Running tests with Hspec
- Passing options to Hspec
- Setting expectations
- Using QuickCheck with Hspec
- Interoperability with HUnit
- Automatic spec discovery
- Running individual spec items
- Speeding up the edit-compile-test cycle
- Parallel spec execution
- Extending Hspec: Writing a custom formatter