In praise of good testing

merlyn on 2006-06-08T15:52:00

In my work for $client, last week I spent a few hours making sure that Devel::Cover was mostly happy with my code, running through enough branches so that when I had to "go live" with minor revisions, I could push the change with a fair degree of confidence.

This week, I concluded that a fundamental data structure (an in-memory hash-of-hashes) that controlled the entire operation and was passed from one part to the next of this 2000-line set of modules, should be changed to be permanent.

So I pulled out Rose::DB, designed a simple main-row-plus-1-to-n-children database schema, and started refactoring. Of course, after I got rid of the initial data structure, every test failed. I would take each test, run it, and watch it fail, and then I would keep hacking the code and fixing it again until the test passed. Then I'd move on to the next one.

Six hours later, my complex application was now completely running with Rose::DB-based persistence instead of an in-memory data structure. And I was very happy that the client had insisted on complete tests before I started, because I was now confident to push this new version into production.

Tests. Not just for breakfast, any more.


Rose::DB

sigzero on 2006-06-09T01:00:40

How do you like that? I have been thinking of trying it with someting.