[Haskell-cafe] HSpec vs Doctest for TDD
qdunkan at gmail.com
Sat Jun 28 17:03:31 UTC 2014
I often write tests first, as a way of testing my understanding. I
figure out in my head what I think a certain function should return,
and write that down first. That way I have a "second implementation"
(the one in my head) that hasn't been compromised by seeing the actual
results. Otherwise I'd be tempted to copy and paste actual output
into the test and inspect it to make sure it makes sense.
I think what kind of tests are relevant depends more strongly on what
kind of program you are writing, than what language you are writing
in. My program has a lot of complexity that's hard to put in types,
and is also not amenable to QuickCheck, so I wind up with lots of
'equal (f x y z) [expected, result, ...]' type tests, and those can
work well if you write them first. It's somewhat similar to compiler,
so it's analogous to ghc's "expected output" and "should fail" tests.
Another style of program could be totally different.
More information about the Haskell-Cafe