Haskell unit tests best pracices

im just starting out with haskell now, is there any set of best practices for unit testing, ei how to organise tests?

2 Likes

hspec tutorial has a nice overview of scaffolding, testing verious properties. It is a very good, very popular, thoroughly documented testing library which is used in many many Haskell projects.

1 Like

“How to organize tests” is not much different than how tests should be organized in any other language.

But in terms of frameworks, hspec and tasty are the two big ones. hspec is more batteries included, while tasty is intended to be extensible, with many plugins to extend the kinds of tests you can write. e.g. the tasty-golden plugin lets you write golden tests, adding CLI flags to tasty to update golden files. hspec doesnt expose a plugin system where plugins can add CLI options, so hspec-golden has to provide a separate executable you have to manually run to update golden files.

Shameless plug: I also wrote tasty-autocollect which lets you write tests more nicely at the top level, which is especially nice with property test frameworks.