Editorial Note: I originally wrote this post for the Infragistics blog. Check out the original here, at their site. If you like this post, please give them some love over there and go check out the original and some of the other posts.
Writing automated tests is sort of like the kale of the software development community. With the exception of a few outlying “get off my lawn” types, there’s near-universal agreement that it’s “the right thing.” And that leaves a few different camps of people.
The equivalent of fast food eating carnivores say, “yeah, that’s something that we ought to do, but it’s not for me.” The equivalent of health-conscious folks plagued by cravings say “we do our best to write tests, but sometimes we just get too busy and we can’t.” And then, finally, the equivalent of the health nut says, “I write tests all the time and can’t imagine life any other way.” A lot of people in the first two camps probably don’t believe this statement. I can understand that, myself, because it’s hard to imagine passing up fried chicken for a kale salad in a universe where calories and cholesterol don’t count.
And yet, I am that ‘health nut’ when it comes to automated testing. I practice test driven development (TDD) and find that it saves me time and makes me more productive on the projects I work.
It is because of that tendency that I’d like to address a common sentiment that I hear in the industry. I suspect you’ve heard variants of these statements before.
- “We started out writing some tests, but we got behind schedule and had to hurry, so we stopped.”
- “TDD doesn’t make sense in the early phase of this project because we’re just prototyping.”
- “We didn’t want to write any tests because there’s a chance that this code might get thrown out and we’d just be writing twice as much code.”
The common thread here is the idea that writing the automated tests is, when the rubber meets the road, a bonus. In the world of software development, the core activity is writing the executable source code and deploying it, and anything else is, strictly speaking, expendable. You don’t truly need to write documentation, generate automated tests, go through QA, update the project milestones in a Gantt chart, etc. All of these things are kale in the world of food — you just need to eat any kind of food, but you’ll eat kale if you’re in the mood and have time to go to the grocery store, and… etc.