[Haskell-cafe] Type System vs Test Driven Development
jake.mcarthur at gmail.com
Wed Jan 5 18:12:13 CET 2011
On 01/05/2011 03:44 AM, Jonathan Geddes wrote:
> When I write Haskell code, I write functions (and monadic actions)
> that are either a) so trivial that writing any kind of unit/property
> test seems silly, or are b) composed of other trivial functions using
> equally-trivial combinators.
"There are two ways of constructing a software design. One way is to
make it so simple that there are obviously no deficiencies. And the
other way is to make it so complicated that there are no obvious
deficiencies." -- C.A.R. Hoare
If you actually manage to do the former, I'd say you don't need to test
those parts in isolation.
That said, I disagree with you overall. The Haskell type system is
simply not rich enough to guarantee everything you might need. Even if
it was, it would take a lot of work to encode all your invariants,
probably more work than writing tests would have been (although there
are obvious advantages to the former as far as having a high level of
assurance that your code is correct).
Haskell has some awesome testing tool, and I highly recommend getting
acquainted with them. In particular, you should definitely learn how to
use QuickCheck, which allows you to easily check high-level properties
about your code; this is beyond what most traditional unit tests could
hope to achieve. I tend to use QuickCheck, SmallCheck, *and*
LazySmallCheck in my test suites, as I feel that they complement each
other well. HUnit is probably the main one for traditional unit tests. I
admit I have never used it, and I'm not sure whether I'm missing out on
anything. There are also some pretty nice test frameworks out there to
help you manage all your tests, although they could probably use a
little more work overall.
More information about the Haskell-Cafe