[Haskell-cafe] TDD in Haskell

Daniel Fischer daniel.is.fischer at web.de
Tue May 25 09:00:54 EDT 2010


On Tuesday 25 May 2010 14:36:46, Ionut G. Stan wrote:
> On 5/25/10 2:50 PM, Daniel Fischer wrote:
> > On Tuesday 25 May 2010 13:36:01, Ionut G. Stan wrote:
> >> Hi,
> >>
> >> I'm doing TDD in pretty much all of the languages that I know, and I
> >> want to introduce it early in my Haskell learning process. I wonder
> >> though, if there's some established process regarding TDD, not unit
> >> testing.
> >>
> >> I've heard of QuickCheck and HUnit, but I've also read that
> >> QuickCheck is used mostly for testing pure code, while HUnit for
> >> impure code?
> >
> > And ghci or hugs are the most used tools for testing, be the code pure
> > or impure.
>
> Well, probably. I'm looking for an automated solution though. I want to
> be able to rerun the tests on every commit or version release.
>

Good practice. You can configure darcs to run the tests on every record (or 
version-tag or whatever).
The testing in ghci/hugs is primarily done while writing the code, after 
that QuickCheck takes over.

> >> What framework lends itself better for writing tests before the
> >> actual production code? Can you point out to some resources regarding
> >> this?
> >
> > You can write the QuickCheck properties that your functions should
> > satisfy before implementing the functions.
> > However, when you've determined the specs, it's rather unimportant
> > whether you write the properties first or the functions, IMO.
>
> It may be true. I've got accustomed though to write code in iterative
> steps, where I first think about the smallest feature that I want to
> implement, then write the test, then again feature -> test ->
> code/refactor.
>
> I will certainly have to adapt my work flow within the Haskell way of
> doing things, until then though I'll start from what I know has produced
> good results for me and change it along the way.
>

You will have to adapt your way of thinking about your tasks to Haskell 
(discover new fun ways of doing things :D), but I see no reason why you 
should stop writing the tests first.
What I meant is, once you know what the function should do, it's not 
important whether you write the Quickcheck property before the function or 
the other way round - you can't run the tests before both are written 
anyway :)
Of course, if you write the tests first, you don't risk omitting them.



More information about the Haskell-Cafe mailing list