liveBook · Manning

Test

As explained in Learn Haskell by Example

Testing is the process of evaluating software behavior to find defects or verify requirements.

Testing evaluates software behavior to find defects and verify requirements. In Haskell, pure functions make this especially direct: compare a function’s output with its specification without adapters, fake environments, or side-effect setup. section 9.0 section 1.2.3

Unit testing checks small, self-contained code units individually. Integration testing examines component interplay, while system testing checks requirements on the finished system; reliable higher-level tests depend on trustworthy lower-level tests. section 9.1

Property testing improves on manually enumerated examples:

  • Express correct behavior as a property relating inputs and outputs. section 9.1
  • Generate many random inputs and check the property for each one. section 9.0 section 9.1
  • Use QuickCheck, or build a small framework, then tailor generators for special cases and incorporate suites into Stack projects. section 9.0

Example-based versus property-based checks

An example-based test supplies a handcrafted input and expects a predetermined result. Property testing instead checks a stated rule across randomly generated inputs, increasing the chance of exposing forgotten edge cases. section 9.1

Figure 9.1 The testing pyramid
figure

Use the testing pyramid to compare unit, integration, and system testing levels. section 9.1

How Learn Haskell by Example covers it

How deep it goes
Develops unit and property testing from motivation through random generation, QuickCheck usage, custom generators, and Stack integration.
Examples
Contrasts handcrafted input-output examples with randomly generated inputs checked against formalized properties.
What it assumes
Assumes Haskell code and clear function specifications while introducing testing levels, properties, random values, and generators.
What you can do after
Builds Haskell property tests with QuickCheck, custom generators, and Stack test suites.
How it connects
Connects unit testing with integration testing, system testing, property testing, QuickCheck, random values, pure functions, and Stack.

Also explained in

Compare how 53 books explain test →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.