News for hackers. Stuff that matters.
Re:Unit testing in Coders at Work by gcv on Tuesday October 06, 2009 @10:14AM (#864145)
As far as testing goes, I have a simple approach.

If I just wrote some code and had to poke at it in a REPL with some different inputs to check if it works, then I should take whatever I did and turn it into a test. With a good testing framework, like the one built into Clojure (formerly clojure.contrib.test-is and now clojure.test), it's really easy. I just copy from my REPL and paste it into the appropriate test file, along with the expected results.

If I find a bug, I fix it, write a test for it, and also copy whatever I did to check my work from the REPL into a test file.

That's it. I routinely change code around with all the confidence TDD advocates claim. I don't test trivialities. I don't test if my database connection was correctly established --- but I will test database connection loss error handling if I put any non-trivial logic in there.

I'll often write a little snippet of sample code for an API I'm working on, but I never write a full formal test in advance. It makes letting the actual API evolve as it grows too cumbersome.

Re:Unit testing in Coders at Work by eru on Tuesday October 06, 2009 @11:27AM (#864344)
Sensible.

Though writing a test case for an evolving API might be of benefit from time to time, because it forces you to use the API (and thus see if it is sensible).