hspec is a general-purpose Haskell testing library for organizing specifications, test cases, and test suites. It distinguishes suites from cases, supports setup for each case, assertions, integration with QuickCheck, SmallCheck, and HUnit, parallel evaluation, and automatic test discovery. section 15.1.1
A practical hspec test keeps one responsibility and follows arrange, act, and assert:
- Arrange the required data or environment. section 15.1.1
- Act by performing the operation under test. section 15.1.1
- Assert the result with an assertion function, while keeping tests independent so parallel execution does not introduce races. section 15.1.1
Specifications for a pure function
A specification groups cases under a topic with describe and expresses expectations using shouldBe. Tests can cover positive, negative, and zero inputs for square without sharing mutable state.
Testing a composed device
A specification can act as a final consumer of an opaque Device: construct it from vendor components, retrieve a named part through getDevicePart, and fail when the component is absent. Fake APIs make this boundary test runnable before production implementations exist.
