Hspec's expectation language is built on top of
HUnit, hence it is possible to use
HUnit assertions instead. E.g. shouldBe is just another name for HUnit's
@?=. You can use whatever you prefer and it will work
seamlessly.
Example code:
runhaskell Spec.hs
reverse
reverses a list [✔]
Finished in 0.0005 seconds
1 example, 0 failures
Running a HUnit test suite with Hspec
fromHUnitTest from the
hspec-contrib package can
be used to convert a HUnit test suite to a Spec. This can be used to run
existing HUnit tests with Hspec. Ordinary spec items and HUnit tests can be
freely intermixed.
Example code:
runhaskell Spec.hs
some ordinary spec items
returns the first element of a list [✔]
some legacy HUnit tests
test_read_is_inverse_to_show [✔]
test_23_is_equal_to_42 [✘]
Failures:
Spec.hs:29:6:
1) some legacy HUnit tests test_23_is_equal_to_42
expected: 42 but got: 23
To rerun use: --match "/some legacy HUnit tests/test_23_is_equal_to_42/"
Randomized with seed 921447365
Finished in 0.0005 seconds
3 examples, 1 failure