Recently, there has been a lot of mention of Test-Driven Development (TDD). It intrigued me, so I decided to use it when building a relatively involved script at work yesterday.
Results:
- It was very difficult, initially, to make the transition. I kept wanting to just write the damn code! I could see it in my head, so why wasn't it on the screen already?!?
- Coming up with tests wasn't easy. The stupid ones that exercise your handling of Getopt::Long were simple. Getting tests that actually exercised code that deals with abstract values ... priceless (as in, I can't afford them!)
- Once I got running, adding functionality was a painless process because I knew each piece work as I built it.
- I certainly got to know my test harness well! (Test::Cmd::Common, in case you're wondering.) This is key because for any non-trivial test, you're going to have (potentially) non-deterministic output. I had to learn some of the advanced features to deal with things like variable dates/times, etc.
- I realized just how much I wasn't testing. This was scary. I have always tested basic O-K and NO-K paths, but I wasn't testing the interactions between them. Now, I can always say that if the parts work, the whole should work, but we all know that is never the case.
- This process did find (and prompt me to fix) at least 2 bugs that would've made it into v1.0 that would've embarassed me in front of my client. For that, I'm thankful.
- I had to put my design on paper. This may be the most important aspect of TDD. I can usually hold most designs in my head, but I've been working on some projects that no-one can hold in their head. (Well, maybe Abigail-II, but not most people.) I don't have the habits of putting stuff on paper to work it through. This will give me those habits.
All in all, I really like it. It definitely forces the developer to design things so that they can be verified. It won't work on all situations, but I know I probably will always work on verifiable tasks. New methodology, here I come!
------
We are the carpenters and bricklayers of the Information Age.
The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.